N
Norbert
I d'like to create a custom Button with two lines of text
Where the second one has a smaller font.
I've done following steps:
Added a new Item (Custom Control) to my Projekt
After this, i changed the parent class of the control to BUTTON
Code of this class:
/////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PPC_TEST_APP
{
public partial class CustomControl1 : Button
{
public CustomControl1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
SizeF textsize = pe.Graphics.MeasureString(Text,
this.Font);
Font myFont = new Font(this.Font.Name, (float)7.0,
this.Font.Style);
Brush myBrush = new SolidBrush (this.ForeColor);
RectangleF myRect= new
RectangleF((textsize.Height),0,this.Width,this.Height-textsize.Height);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
// Calling the base class OnPaint
//base.OnPaint(pe);
pe.Graphics.DrawString("Hello World", myFont, myBrush,
myRect, sf);
}
}
}
/////////////////////////////////////////////////////
After adding this to a Form (drag & drop through designer)
I get a wired behavior.
The OnPaint Method never gets called (tried to debug)
Somebody knows why?
Isn't it possible to derive from a Button?
Or must I create a nwe Button class from the scratch?
regards
Norbert
Where the second one has a smaller font.
I've done following steps:
Added a new Item (Custom Control) to my Projekt
After this, i changed the parent class of the control to BUTTON
Code of this class:
/////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PPC_TEST_APP
{
public partial class CustomControl1 : Button
{
public CustomControl1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
SizeF textsize = pe.Graphics.MeasureString(Text,
this.Font);
Font myFont = new Font(this.Font.Name, (float)7.0,
this.Font.Style);
Brush myBrush = new SolidBrush (this.ForeColor);
RectangleF myRect= new
RectangleF((textsize.Height),0,this.Width,this.Height-textsize.Height);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
// Calling the base class OnPaint
//base.OnPaint(pe);
pe.Graphics.DrawString("Hello World", myFont, myBrush,
myRect, sf);
}
}
}
/////////////////////////////////////////////////////
After adding this to a Form (drag & drop through designer)
I get a wired behavior.
The OnPaint Method never gets called (tried to debug)
Somebody knows why?
Isn't it possible to derive from a Button?
Or must I create a nwe Button class from the scratch?
regards
Norbert