حاشیه دار کردن کنترل TextBox با یک رنگ دلخواه در کلاس TextBox خود (و یا سایر کنترلهای دلخواه : کامبوباکس، لیست باکس و ...) بنویسید : کد: private static int WM_NCPAINT = 0x0085; private static int WM_ERASEBKGND = 0x0014; private static int WM_PAINT = 0x000F; [DllImport("user32.dll")] static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgnclip, uint fdwOptions); [DllImport("user32.dll")] static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC); protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_NCPAINT || m.Msg == WM_ERASEBKGND || m.Msg == WM_PAINT) { IntPtr hdc = GetDCEx(m.HWnd, (IntPtr)1, 1 | 0x0020); if (hdc != IntPtr.Zero) { Graphics graphics = Graphics.FromHdc(hdc); Color borderColor = Color.Blue; Rectangle rectangle = new Rectangle(0, 0, this.Width, this.Height); ControlPaint.DrawBorder(graphics, rectangle, borderColor, ButtonBorderStyle.Solid); m.Result = (IntPtr)1; ReleaseDC(m.HWnd, hdc); } }
پاسخ : 1001نکته در سی شارپ محو شدن تدریجی یک فرم با تغییر دادن خاصیت Opacity کد: کد: private void button1_Click(object sender, EventArgs e) { this.Opacity = 1; for (int i = 0; i < 100; i++) { this.Opacity -= 0.01; Application.DoEvents(); } } this به آبجکت فعلی از فرم اشاره دارد.
پاسخ : 1001نکته در سی شارپ انتقال آیتمهای یک آرایه از اعداد به یک لیست باکس کد: کد: int[] numbers = { 12, 23, 34, 45, 56, 67 }; Object[] oNumbers = new Object[numbers.Length]; numbers.CopyTo(oNumbers, 0); listBox1.Items.AddRange(oNumbers);
پاسخ : 1001نکته در سی شارپ پیاده سازی حالت ساده ی الگوی سینگلتون در یک کلاس کد: sealed class SingletonClass { // Static members are lazily initialized. // .NET guarantees thread safety for static initialization private static readonly SingletonClass instance = new SingletonClass(); // Note: constructor is private. private SingletonClass(){} public static SingletonClass GetInstance() { return instance; } }
پاسخ : 1001نکته در سی شارپ رسم یک چندضلعی توپر روی یک فرم کد: private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; // Create pen. Pen blackPen = new Pen(Color.Black, 3); // Create points that define polygon. Point point1 = new Point(30, 50); Point point2 = new Point(100, 25); Point point3 = new Point(200, 5); Point point4 = new Point(250, 50); Point point5 = new Point(270, 100); Point point6 = new Point(250, 250); Point[] curvePoints = {point1, point2, point3, point4, point5, point6}; // Draw polygon to screen. g.DrawPolygon(blackPen, curvePoints); // Fill polygon g.FillPolygon(Brushes.Red, curvePoints); }