Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > Расположение элементов в окне


Автор: vintyara 17.3.2008, 13:57
Hi all. Пытаюсь учить C#. Никак не могу понять - как создавать в одном графическом окне (окно умею создавать) несколько, скажем, кнопок и лейблов, и как задавать им позиции в этом окне (например лейблы справа, кнопки слева одно под другой) ?? Кто подскажет?

ЗЫ редактор интерфейсов Glade не использую и пока не хочу. хочу сначало без него понять принцип.

Автор: Freak_FB 17.3.2008, 14:52
Можешь для начала посмотреть, как это делает IDE:
Код

namespace dotNET_DDE_Server
{
    partial class SelectCOMPortForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (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()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SelectCOMPortForm));
            this.lbSerialPorts = new System.Windows.Forms.ListBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.chkShowAll = new System.Windows.Forms.CheckBox();
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnOK = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // lbSerialPorts
            // 
            this.lbSerialPorts.AccessibleDescription = null;
            this.lbSerialPorts.AccessibleName = null;
            resources.ApplyResources(this.lbSerialPorts, "lbSerialPorts");
            this.lbSerialPorts.BackgroundImage = null;
            this.lbSerialPorts.Font = null;
            this.lbSerialPorts.FormattingEnabled = true;
            this.lbSerialPorts.Name = "lbSerialPorts";
            this.lbSerialPorts.SelectedIndexChanged += new System.EventHandler(this.lbSerialPorts_SelectedIndexChanged);
            // 
            // groupBox1
            // 
            this.groupBox1.AccessibleDescription = null;
            this.groupBox1.AccessibleName = null;
            resources.ApplyResources(this.groupBox1, "groupBox1");
            this.groupBox1.BackgroundImage = null;
            this.groupBox1.Controls.Add(this.chkShowAll);
            this.groupBox1.Controls.Add(this.lbSerialPorts);
            this.groupBox1.Font = null;
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.TabStop = false;
            // 
            // chkShowAll
            // 
            this.chkShowAll.AccessibleDescription = null;
            this.chkShowAll.AccessibleName = null;
            resources.ApplyResources(this.chkShowAll, "chkShowAll");
            this.chkShowAll.BackgroundImage = null;
            this.chkShowAll.Font = null;
            this.chkShowAll.Name = "chkShowAll";
            this.chkShowAll.UseVisualStyleBackColor = true;
            this.chkShowAll.CheckedChanged += new System.EventHandler(this.chkShowAll_CheckedChanged);
            // 
            // btnCancel
            // 
            this.btnCancel.AccessibleDescription = null;
            this.btnCancel.AccessibleName = null;
            resources.ApplyResources(this.btnCancel, "btnCancel");
            this.btnCancel.BackgroundImage = null;
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = null;
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            // 
            // btnOK
            // 
            this.btnOK.AccessibleDescription = null;
            this.btnOK.AccessibleName = null;
            resources.ApplyResources(this.btnOK, "btnOK");
            this.btnOK.BackgroundImage = null;
            this.btnOK.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnOK.Font = null;
            this.btnOK.Name = "btnOK";
            this.btnOK.UseVisualStyleBackColor = true;
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // SelectCOMPortForm
            // 
            this.AcceptButton = this.btnOK;
            this.AccessibleDescription = null;
            this.AccessibleName = null;
            resources.ApplyResources(this, "$this");
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackgroundImage = null;
            this.CancelButton = this.btnCancel;
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.groupBox1);
            this.Font = null;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "SelectCOMPortForm";
            this.Load += new System.EventHandler(this.SelectCOMPortForm_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.ListBox lbSerialPorts;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.CheckBox chkShowAll;
        private System.Windows.Forms.Button btnCancel;
        private System.Windows.Forms.Button btnOK;
    }
}

Автор: vponomarov 17.3.2008, 15:37
Freak_FB, по-моему автор имел в виду как это сделать в WPF...

Автор: vintyara 17.3.2008, 15:43
Freak_FB, у меня линукс + mono - Windows.Forms нету.

vponomarov, не знаю что такое WPF.

Вот у меня есть один_файл.cs

В нем я создал окно

Код

...
 Window w = new Window("Puzle ;)");
 w.Resize(420,320);
...


Вот теперь хочу в нем кнопочек добавить. Если программно я еще более менее понимаю как добавить, то как программно задать их расположение - понять не могу.

Автор: vponomarov 17.3.2008, 16:37
vintyara, так надо было сразу сказать, что ты под линуксом програмишь smile 

Автор: vintyara 17.3.2008, 16:55
каюсь  smile 

Автор: vintyara 18.3.2008, 12:45
Хмм.. Неужели никто не знает?  smile 

Автор: _hunter 18.3.2008, 13:32
дык уже ж ответили:
Цитата(Freak_FB @  17.3.2008,  13:52 Найти цитируемый пост)
Можешь для начала посмотреть, как это делает IDE:

првда там нет именно координат... но это ничего не меняет:
Button button = new Button();
button.Parent = w;
button.Top = 10;
...

Автор: Freak_FB 18.3.2008, 14:28
Ну да, координат нет... Там они из ресурсов берутся.
Свойства Location и Size нужно установить.
Код

button1.Location = new Location(20, 20);
button1.Size = new Size(50, 20);


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)