powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / WinForms: показ главного окна
4 сообщений из 4, страница 1 из 1
WinForms: показ главного окна
    #32475751
gerss
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Привет всем!

Есть такая проблема - при запуске приложения необходимо показать диалоговое окно соединения с БД. Показ делаю на событии Load главного окна; главное окно при этом видимо. Как сделать так, чтобы главное окно не показывалось до тех пор, пока не будет закрыто диалоговое окно соединения с БД?


Сергей
...
Рейтинг: 0 / 0
WinForms: показ главного окна
    #32476410
2115
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Вызывай диалоговое окно до создания главного окна
...
Рейтинг: 0 / 0
WinForms: показ главного окна
    #32479898
olk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
// -----------------------------------------------------------
 
// LoginDialog.cs
// -----------------------------------------------------------
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Login
{
	/// <summary>
	/// Summary description for LoginDialog.
	/// </summary>
	public class LoginDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.Button buttonCancel;

		public ApplicationContext m_applicationContext;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public LoginDialog(ApplicationContext applicationContext)
		{
			m_applicationContext = applicationContext;  
			m_applicationContext.MainForm = this;

			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.buttonOK = new System.Windows.Forms.Button();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// buttonOK
			// 
			this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.buttonOK.Location = new System.Drawing.Point( 52 ,  216 );
			this.buttonOK.Name =  "buttonOK" ;
			this.buttonOK.TabIndex =  0 ;
			this.buttonOK.Text =  "OK" ;
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
			// 
			// buttonCancel
			// 
			this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.buttonCancel.Location = new System.Drawing.Point( 168 ,  216 );
			this.buttonCancel.Name =  "buttonCancel" ;
			this.buttonCancel.TabIndex =  1 ;
			this.buttonCancel.Text =  "Cancel" ;
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// LoginDialog
			// 
			this.AcceptButton = this.buttonOK;
			this.AutoScaleBaseSize = new System.Drawing.Size( 5 ,  13 );
			this.CancelButton = this.buttonCancel;
			this.ClientSize = new System.Drawing.Size( 292 ,  273 );
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.buttonOK);
			this.Name =  "LoginDialog" ;
			this.Text =  "Окно соединения с БД" ;
			this.ResumeLayout(false);

		}
		#endregion

		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			MainForm m_form = new MainForm();  
			m_applicationContext.MainForm = m_form;  
			Close();  
			m_form.ShowDialog();
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

	}
}



Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
// -----------------------------------------------------------
 
// MainForm.cs
// -----------------------------------------------------------
 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Login
{
	/// <summary>
	/// Summary description for MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size( 5 ,  13 );
			this.ClientSize = new System.Drawing.Size( 292 ,  273 );
			this.Name =  "MainForm" ;
			this.Text =  "Основная форма" ;

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
		  ApplicationContext applicationContext = new ApplicationContext();
		  LoginDialog loginDialog  = new LoginDialog(applicationContext);  
		  Application.Run(applicationContext);
				  
		}
	}
}
...
Рейтинг: 0 / 0
WinForms: показ главного окна
    #32481365
gerss
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
2olk:
Спасибо. Делаю примерно так, только не создаю ApplicationContext, а просто показываю диалог до Application.Run(...);

Чем твой способ лучше/хуже? Что вообще дает ApplicationContext в этом случае?

Сергей

PS: Вопрос не праздный - я новичок в C# и это действительно интересно.
PPS: можно в мыло - адрес в профиле.
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / WinForms: показ главного окна
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]