بعنوان مثال من یه دونه label دارم که میخوام رنگش رو به قرمز تغییر بدم
lbl1.ForeColor = System.Drawing.Color.Red;
بعنوان مثال من یه دونه label دارم که میخوام رنگش رو به قرمز تغییر بدم
lbl1.ForeColor = System.Drawing.Color.Red;
متد زیر رو داخل کلاستون کپی کنین
void ClearAllText(Control con)
{
foreach (Control c in con.Controls)
{
if (c is TextBox)
((TextBox)c).Clear();
else
ClearAllText(c);
}
}
بعد اون هرجا که نیاز داشتین با صدا زدن متد اطلاعات تمام Textbox های موجود در فرم پاک میشه
ClearAllText(this);
e.Cancel = trueحتی قبلش میتونین یک messageBox بذارین که از کاربر بپرسه مایل به خروج از برنامه هست یا نه اگه مایل به خروج بود خاصیت فوق را false کن در غیر اینصورت True کن
برای مثال قصد داریم اطلاعات موجود یک textbox که تو Form1 هستش رو به textbox موجود درون Form2 منتقل کنیم.
رو Form1 یه دونه textbox و یه دونه هم button میذاریم.
دستورات مربوط به button :
Private void Button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2(textBox1.Text);
form2.Show();
}
حالا وارد Form2 بشید و یه دونه textbox داخلش بذارید
حالا تو متد سازندتون که هم نام با کلاستون هست دستور زیر رو وارد کنین
public Form2(string textbox1)
{
InitializeComponent();
TextBox1.Text = textbox1;
}
بعضی مواقع یه text box تو فرم دارید و نیاز دارین که فقط کاربر بتونه عدد وارد کنه واسه اعمال این فیلتر کد زیر رو داخل رویداد KeyPrees تکست باکست وارد کنین
private void txt_phoneNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)))
{
e.Handled = true;
}
}
private void myform_FormClosing(object sender, FormClosingEventArgs e)
{
this.Opacity = 1;
for (int i = 0; i < 100; i++)
{
this.Opacity -= 0.01;
Application.DoEvents();
System.Threading.Thread.Sleep(10);
}
}
1- طبق تصویر زیر یه دکمه روی فرم قرار بدید
private void btn_shot_Click(object sender, EventArgs e)
{
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
Graphics Graphics;
Bitmap Bitmap = new Bitmap(screenWidth, screenHeight);
Graphics = Graphics.FromImage(Bitmap);
Graphics.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
Bitmap.Save(@"D:\ScreenShot.bmp");
}