Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TextBox textBox = new TextBox();
- textBox.Font = new Font("Calibri", 11);
- textBox.Dock = DockStyle.Fill;
- textBox.Multiline = true;
- textBox.WordWrap = false;
- textBox.ScrollBars = ScrollBars.Vertical;
- Form form = new Form();
- form.Text = "Recipe";
- form.Size = new Size(400, 600);
- form.FormBorderStyle = FormBorderStyle.Sizable;
- form.StartPosition = FormStartPosition.CenterScreen;
- form.Controls.Add(textBox);
- Graphics g = form.CreateGraphics();
- float targetWidth = 230;
- foreach (PropertyInfo property in properties)
- {
- string text = String.Format("{0}:t", Description);
- while (g.MeasureString(text,textBox.Font).Width < targetWidth)
- text += "t";
- textBox.AppendText(text + value.ToString() + "n");
- }
- g.Dispose();
- form.ShowDialog();
- Private Declare Function SendMessage _
- Lib "user32" Alias "SendMessageA" _
- (ByVal handle As IntPtr, ByVal wMsg As Integer, _
- ByVal wParam As Integer, ByRef lParam As Integer) As Integer
- Private Sub SetTabStops(ByVal ctlTextBox As TextBox)
- Const EM_SETTABSTOPS As Integer = &HCBS
- Dim tabs() As Integer = {20, 40, 80}
- SendMessage(ctlTextBox.Handle, EM_SETTABSTOPS, _
- tabs.Length, tabs(0))
- End Sub
- using System.Runtime.InteropServices;
- private const int EM_SETTABSTOPS = 0x00CB;
- [DllImport("User32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam);
- private void SetTabStops(TextBox ctlTextBox)
- {
- const int EM_SETTABSTOPS = 203;
- int[] tabs = { 100, 40, 80 };
- SendMessage(textBox1.Handle, EM_SETTABSTOPS, tabs.Length, tabs);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- SetTabStops(textBox1);
- textBox1.Text = "HitWorld";
- }
- // This is a better way to pass in what tab stops I want...
- SetTabStops(textBox, new int[] { 12,120 });
- // And the code for the SetTabsStops method itself...
- private const uint EM_SETTABSTOPS = 0x00CB;
- [DllImport("User32.dll")]
- private static extern uint SendMessage(IntPtr hWnd, uint wMsg, int wParam, int[] lParam);
- public static void SetTabStops(TextBox textBox, int[] tabs)
- {
- SendMessage(textBox.Handle, EM_SETTABSTOPS, tabs.Length, tabs);
- }
Add Comment
Please, Sign In to add comment