Click here to Skip to main content
15,914,419 members
Home / Discussions / C#
   

C#

 
GeneralHelp on setting index of dropdownlist. Pin
macsgirl21-Sep-04 9:46
macsgirl21-Sep-04 9:46 
GeneralRe: Help on setting index of dropdownlist. Pin
Colin Angus Mackay21-Sep-04 12:00
Colin Angus Mackay21-Sep-04 12:00 
GeneralRe: Help on setting index of dropdownlist. Pin
macupryk21-Sep-04 12:32
macupryk21-Sep-04 12:32 
GeneralRe: Help on setting index of dropdownlist. Pin
Colin Angus Mackay21-Sep-04 12:47
Colin Angus Mackay21-Sep-04 12:47 
GeneralRe: Help on setting index of dropdownlist. Pin
macupryk21-Sep-04 13:00
macupryk21-Sep-04 13:00 
GeneralRe: Help on setting index of dropdownlist. Pin
Colin Angus Mackay21-Sep-04 13:12
Colin Angus Mackay21-Sep-04 13:12 
GeneralConfigurable font height/width Pin
Yaron K.21-Sep-04 7:44
Yaron K.21-Sep-04 7:44 
GeneralRe: Configurable font height/width Pin
Heath Stewart21-Sep-04 11:33
protectorHeath Stewart21-Sep-04 11:33 
Fonts are graphical representation of characters and are designed to resize proportionally. If you need to resize them disproportionately, then you'll need to transform them.

One way would be to either create a new Graphics device or to adjust your math - if possible - to account for the transformation you'll be performing to the Graphics object.

To perform the transformation, you can use a myriad of methods on the Graphics class - all documented in the .NET Framework SDK. One such method follows:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
class Test : Form
{
  static void Main()
  {
    Application.Run(new Test());
  }
 
  Test()
  {
    StretchLabel lbl = new StretchLabel();
    Controls.Add(lbl);
    lbl.Dock = DockStyle.Fill;
    lbl.ScaleHeight = 4f;
    lbl.Font = new Font(Font.FontFamily, 20f);
    lbl.ScaleWidth = 2f;
    lbl.Text = "Sample";
 
    Text = "Sample";
  }
}
 
class StretchLabel : Label
{
  SizeF size = SizeF.Empty;
  float scaleWidth = 1f;
  float scaleHeight = 1f;
 
  [DefaultValue(1f)]
  public float ScaleWidth
  {
    get { return scaleWidth; }
    set { scaleWidth = value; }
  }
 
  [DefaultValue(1f)]
  public float ScaleHeight
  {
    get { return scaleHeight; }
    set { scaleHeight = value; }
  }
 
  protected override void OnTextChanged(EventArgs e)
  {
    using (Graphics g = CreateGraphics())
      size = g.MeasureString(Text, Font, (SizeF)Size);
 
    base.OnTextChanged(e);
  }
 
  protected override void OnPaint(PaintEventArgs e)
  {
    Graphics g = e.Graphics; // DO NOT dispose this Graphics object.
    g.ScaleTransform(scaleWidth, scaleHeight, MatrixOrder.Append);
    g.DrawString(Text, Font, new SolidBrush(ForeColor), PointF.Empty);
 
    base.OnPaint(e);
  }
}
Pay close attention to the Graphics.ScaleTransform, which I recommend reading about in the .NET Framework SDK.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: Configurable font height/width Pin
Yaron K.21-Sep-04 19:01
Yaron K.21-Sep-04 19:01 
GeneralRe: Configurable font height/width Pin
Yaron K.22-Sep-04 22:37
Yaron K.22-Sep-04 22:37 
Generalproblem with c# (help required) Pin
Anonymous21-Sep-04 7:30
Anonymous21-Sep-04 7:30 
GeneralRe: problem with c# (help required) Pin
tdciDoug21-Sep-04 10:39
tdciDoug21-Sep-04 10:39 
GeneralRe: problem with c# (help required) Pin
Christian Graus21-Sep-04 10:44
protectorChristian Graus21-Sep-04 10:44 
GeneralHelp with books Pin
krisst_k21-Sep-04 7:21
krisst_k21-Sep-04 7:21 
GeneralRe: Help with books Pin
Werdna22-Sep-04 6:18
Werdna22-Sep-04 6:18 
GeneralC# Downloader Pin
shiraztk21-Sep-04 7:11
shiraztk21-Sep-04 7:11 
GeneralRe: C# Downloader Pin
Dave Kreskowiak21-Sep-04 8:34
mveDave Kreskowiak21-Sep-04 8:34 
GeneralRe: C# Downloader Pin
Alex Korchemniy21-Sep-04 10:24
Alex Korchemniy21-Sep-04 10:24 
GeneralRe: C# Downloader Pin
Heath Stewart21-Sep-04 11:16
protectorHeath Stewart21-Sep-04 11:16 
GeneralRe: C# Downloader Pin
shiraztk21-Sep-04 18:03
shiraztk21-Sep-04 18:03 
GeneralRe: C# Downloader Pin
Heath Stewart22-Sep-04 6:46
protectorHeath Stewart22-Sep-04 6:46 
GeneralDatabase access freezing main application Pin
Jon G21-Sep-04 6:02
Jon G21-Sep-04 6:02 
GeneralRe: Database access freezing main application Pin
Nick Parker21-Sep-04 6:56
protectorNick Parker21-Sep-04 6:56 
GeneralRe: Database access freezing main application Pin
Jon G21-Sep-04 7:09
Jon G21-Sep-04 7:09 
GeneralSubscribing multiple forms to a single Resize event Pin
Bisbal21-Sep-04 5:16
sussBisbal21-Sep-04 5:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.