Changing Fontsizes in Controls
-
It is always the simple things that get ya'. Is it me or does MS INSIST on making the easy things hard to do? All I need to do is increase the fontsize of a control. Seems I should be able to just add to the current fontsize, but of course I am not allowed to do that. Oh by the way I can't use the Font Dialog. Here is what I've come up with. Anyone have any better ideas? private void button3_Click(object sender, System.EventArgs e) { System.Drawing.Font currentFont= listBox1.Font; FontStyle fs= currentFont.Style; switch (currentFont.Size.ToString()) { case "8": listBox1.Font = new Font(currentFont.FontFamily, 10, fs); break; case "10": listBox1.Font = new Font(currentFont.FontFamily, 12, fs); break; case "12": listBox1.Font = new Font(currentFont.FontFamily, 15, fs); break; case "15": listBox1.Font = new Font(currentFont.FontFamily, 8, fs); break; } } Thanks in advance. WhiteWizard(aka Gandalf)
-
It is always the simple things that get ya'. Is it me or does MS INSIST on making the easy things hard to do? All I need to do is increase the fontsize of a control. Seems I should be able to just add to the current fontsize, but of course I am not allowed to do that. Oh by the way I can't use the Font Dialog. Here is what I've come up with. Anyone have any better ideas? private void button3_Click(object sender, System.EventArgs e) { System.Drawing.Font currentFont= listBox1.Font; FontStyle fs= currentFont.Style; switch (currentFont.Size.ToString()) { case "8": listBox1.Font = new Font(currentFont.FontFamily, 10, fs); break; case "10": listBox1.Font = new Font(currentFont.FontFamily, 12, fs); break; case "12": listBox1.Font = new Font(currentFont.FontFamily, 15, fs); break; case "15": listBox1.Font = new Font(currentFont.FontFamily, 8, fs); break; } } Thanks in advance. WhiteWizard(aka Gandalf)
If you want to increase fontsize, then see this:
float fontsize = this.listBox1.Font.Size;
fontsize++;
this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif",
fontsize,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
((System.Byte)(0))); -
If you want to increase fontsize, then see this:
float fontsize = this.listBox1.Font.Size;
fontsize++;
this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif",
fontsize,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));Thanks! I combined your code with mine and got just what I needed. Here's what I ended up with: private void button3_Click(object sender, System.EventArgs e) { System.Drawing.Font currentFont= listBox1.Font; FontStyle fs= currentFont.Style; float fontsize = this.listBox1.Font.Size; fontsize++; if (fontsize > 20) { fontsize = 8; } listBox1.Font = new Font(currentFont.FontFamily, fontsize, fs); } Gandalf