|
پروژه ها و سورس هاي آماده ي برنامه نويسي
|
|
|
|
||||
|
تبديل اندازه colomn هاي يك سطر datagridview به حداكثر تعداد كاراكتر در همون ستون private void CalculateWideOfColomn(Graphics g) { SizeF tmpSize = new SizeF(); for (int i = 0; i <= dataGridView1.Columns.Count - 1; i++) { Font tmpFont = dataGridView1.DefaultCellStyle.Font; tmpSize = g.MeasureString(dataGridView1.Columns[i].HeaderText, tmpFont); float tmpWidth = tmpSize.Width; float RowHeaderHeight = tmpSize.Height; for (int j = 0; j <= dataGridView1.Rows.Count - 1; j++) { tmpSize = g.MeasureString("HELLO", tmpFont); tmpSize = g.MeasureString(dataGridView1.Rows[j].Cells[i].EditedFormattedValue.ToString(), tmpFont); if (tmpSize.Width > tmpWidth) { tmpWidth = tmpSize.Width; } } if (dataGridView1.Columns[i].Visible) dataGridView1.Columns[i].Width = (int)tmpWidth; } } - بررسی اتصال به اینترنت Dial up و ADSL در صورتیکه مقدار بازگردانده شده از این تابع IsConnectedToInternet برابر true باشد ، سیستم به اینترنت متصل است کد: using System.Runtime.InteropServices; کد: //بررسی اتصال به اینترنت [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int Description, int ReservedValue); //Creating a function that uses the API function... bool IsConnectedToInternet() { bool a; int Desc; a=InternetGetConnectedState(out Desc, 0); return a; } - قطع کردن اتصال اینترنت دایل آپ از طریق دستورات خط فرمان System.Diagnostics.Process.Start("rasdial", "/disconnect"); - تبدیل اتوماتیک دکمه Enter به Tab جهت انتقال فوکوس در کنترلها private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) SendKeys.Send("{TAB}"); } - گرفتن کد اسکی و یونیکد کاراکتر ها البته راه های بهتری هم هست اما اینو هم داشته باشید... تبدیل به یونیکد کد: String ucode = String.Format("{0:x4}", (int)('a')); // ucode = 0061 تبدیل به اسکی کد: String acode = (((int)('a')).ToString()); //acode=97 - ترسیم و نوشتن مستقیم بر دسکتاپ ویندوز using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; [DllImport("user32")]
internal static extern IntPtr GetDC(IntPtr hwnd); [DllImport("User32.dll")] internal static extern void ReleaseDC(IntPtr dc); public void PaintRectangleToScreen() { IntPtr deskDC = GetDC(IntPtr.Zero); Graphics g = Graphics.FromHdc(deskDC); Font font = new Font("Arial Black", 36); DrawStringOnCenter(g, " font = new Font("Arial Black", 18); DrawStringOnCenter(g, "by: Sinpin", font, new Point(0, 25)); Rectangle rect = new Rectangle(200, 300, Screen.PrimaryScreen.Bounds.Width - 400, Screen.PrimaryScreen.Bounds.Height - 600); g.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.DodgerBlue)) , rect); g.DrawRectangle(new Pen(Color.DodgerBlue, 3), rect); g.Dispose(); ReleaseDC(deskDC); } private void DrawStringOnCenter(Graphics g, string str, Font font, Point offset) { SizeF size = g.MeasureString(str, font); g.DrawString(str, font, Brushes.White, new PointF( (Screen.PrimaryScreen.Bounds.Width - size.Width) / 2 + offset.X, (Screen.PrimaryScreen.Bounds.Height - size.Height) / 2 + offset.Y) ); } و مثالی از طریقه ی استفاده : private void Form1_Load(object sender, EventArgs e) { PaintRectangleToScreen(); this.Close(); منبع کد ها : http://barnamenevis.org |
|||||
|
|||||