PDA

View Full Version : سوال: کنترل کنترلهای یک فرم همراه خود فرم



voice.of.silence
دوشنبه 09 مرداد 1391, 21:41 عصر
سلام دوستان:
من برای برنامه ام می خواهم یک Option بنویسم اما هر کاری که کردم نتوانستم با استفاده از فرم مربوطه کنترلها ویا مشخصات فرم اصلی را ویرایش کنم (تغییر دهم) .
البته کمی توانستم که کنترلها را کنترل کنم اما نتوانستم که مشخصات فرم همچون اندازه، رنگ و ... آن را تغییر دهم.

لطفا مرا در این مورد کمک و یا راهنمایی نمایید.

با سپاس .
Voice of Silence

ali_habibi1384
دوشنبه 09 مرداد 1391, 22:50 عصر
اين كلاسو بهت ميدم كه توي برنامه هاي خودم ازش استفاده ميكنم. برو حالشو ببر. فقط كافيه توي رويداد لود فرم از كلاسش استفاده كني.:چشمک:
تغييراتي مثل lable,textbox,grid,... همشو نمونه هاشو داره. حتي اگر گروپ باكس هم استفاده كرده باشي توي اونا رو هم برات ميگرده واست ميكنه


namespace AccountingMe.Class.ShareClass
{
class SetInterface
{

public static void LoadSkin(Control root )
{



foreach (Control ctl in root.Controls)
{
LoadSkin(ctl);

if (ctl is Label )
{
//ctl.AutoSize = true;
ctl.Font = new System.Drawing.Font("B Roya", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
}
if (ctl is TextBoxtest.TxtProNet )
{
TextBoxtest.TxtProNet tmp;
tmp = (TextBoxtest.TxtProNet)ctl;
tmp.FocusBackColor = System.Drawing.Color.Yellow;
tmp.FocusFont = new System.Drawing.Font("B Roya", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.FocusForeColor = System.Drawing.Color.Blue;
tmp.FocusTextSelect = true;
tmp.Font = new System.Drawing.Font("B Roya", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.RightToLeft = System.Windows.Forms.RightToLeft.No;
tmp.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
}
if (ctl is TextBox )
{
TextBox tmp;
tmp = (TextBox)ctl;
tmp.Font = new System.Drawing.Font("B Roya", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.RightToLeft = System.Windows.Forms.RightToLeft.No;
tmp.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
}
if (ctl is Button )
{
Button tmp;
tmp = (Button)ctl;
tmp.Cursor = System.Windows.Forms.Cursors.Hand;
tmp.Font = new System.Drawing.Font("B Titr", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.UseVisualStyleBackColor = true;
}
if (ctl is CheckBox)
{
CheckBox tmp;
tmp = (CheckBox)ctl;
tmp.AutoSize = true;
tmp.Font = new System.Drawing.Font("B Roya", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
// tmp.Size = new System.Drawing.Size(84, 31);
tmp.UseVisualStyleBackColor = true;
}
if (ctl is ComboBox)
{
ComboBox tmp;
tmp = (ComboBox)ctl;

tmp.Font = new System.Drawing.Font("B Roya", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.FormattingEnabled = true;

// tmp.Size = new System.Drawing.Size(164, 33);

}
if (ctl is TreeView)
{

TreeView tmp;
tmp = (TreeView)ctl;
tmp.Font = new System.Drawing.Font("B Roya", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
tmp.RightToLeftLayout = true;
}
if (ctl is TabControl)
{
TabControl tmp;
tmp = (TabControl)ctl;
tmp.Font = new System.Drawing.Font("B Titr", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
tmp.RightToLeftLayout = true;
// tmp.Size = new System.Drawing.Size(779, 467);
}

if (ctl is DataGridView)
{
DataGridView tmp;
tmp = (DataGridView)ctl;
tmp.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
tmp.MultiSelect = false;
tmp.ReadOnly = true;
tmp.RightToLeft = RightToLeft.Yes;
tmp.BorderStyle = BorderStyle.Fixed3D;
tmp.AllowUserToAddRows = false;
//tmp.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
// | System.Windows.Forms.AnchorStyles.Left)
// | System.Windows.Forms.AnchorStyles.Right)));
tmp.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
tmp.ColumnHeadersDefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment. MiddleLeft;
tmp.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.SystemColors.Control;
tmp.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("B Titr", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.ColumnHeadersDefaultCellStyle.ForeColor = System.Drawing.SystemColors.WindowText;
tmp.ColumnHeadersDefaultCellStyle.SelectionBackCol or = System.Drawing.SystemColors.Highlight;
tmp.ColumnHeadersDefaultCellStyle.SelectionForeCol or = System.Drawing.SystemColors.HighlightText;
tmp.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeig htSizeMode.AutoSize;
tmp.DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment. MiddleLeft;
tmp.RowsDefaultCellStyle.BackColor = System.Drawing.SystemColors.Window;
tmp.RowsDefaultCellStyle.Font = new System.Drawing.Font("B Roya", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
tmp.RowsDefaultCellStyle.ForeColor = System.Drawing.SystemColors.ControlText;
tmp.RowsDefaultCellStyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
tmp.RowsDefaultCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
tmp.MultiSelect = false;
}


}

}
}
}

voice.of.silence
سه شنبه 10 مرداد 1391, 10:04 صبح
سلام دوست عزیز:
از این که کدهای فوق را در اینجا قرار دادی ممنونم.
لطفا اگر ممکن است خود کلاس را در این تاپیک بگذارید. زیرا من کد های بالا را اجرا کردم ولی برنامه با خطا روبه رو شد.
من خیلی تلاش کردم اما آخر نفهمیدم که اشکال در کجاست؟
با سپاس .
voice of Silence