By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,054 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,054 IT Pros & Developers. It's quick & easy.

Custom Buttons & Text Placement [C# Win]

P: n/a
Hi Everyone,

I'm having a problem trying to place text with in my custom buttons. The
problem is that I'm trying to display my text just as if it were a regular
'win' button, I have tried using Rectangle (which is good) & also by
inputting regular attributes. The thing is that, it is unknown how many
words will be displayed & breaks between the words, if there are any.at
runtime. I have tried developing the syntax to account for all possibilities
but it seems endless.

Does anyone have a solution to this problem of mine? I also have tried
surfing Bob Powell's site for info. My code is as follows. Thanks all in
advance.

MikeY

//------------------------------------------------------------

int Point_Width = 5;

int Point_Height = 5;

Font drawFont = new System.Drawing.Font("Tahoma", 8F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));

//Colour Of The Text

SolidBrush drawBrush = new SolidBrush(Color.Black);

//Converts Input Text To Upper Characters

string Input_Text = this.Text.ToUpper();

//Align Text To The Center Of The Button

StringFormat sf = new StringFormat();

sf.Alignment = StringAlignment.Center;

//Text Size

SizeF Text_Size = myGraphics.MeasureString(Input_Text, Font);

char[] separator = {' '};

string[] myWords;

myWords = Input_Text.Split(separator);

if(myWords.Length == 1)

{

Point_Height = 17;

}

else if(myWords.Length == 2)

{

Point_Height = 10;

}

else if(myWords.Length == 3)

{

Point_Height = 5;

}

myGraphics.DrawString(Input_Text, drawFont, drawBrush, new Rectangle(new
Point (Point_Width,Point_Height), new Size(ClientRectangle.Width - 5,
ClientRectangle.Height -5)), sf);

//Display Button In Parent Form

this.Region = new Region(myGraphicsPath);

drawBrush.Dispose();

myPen.Dispose();

myGraphicsPath.Dispose();

Sep 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Doh,

I found my solution back at Bob Powell's site. Link is as follows.

http://www.bobpowell.net/begintext.htm

MikeY

"MikeY" <mi*******@yaho.comwrote in message
news:eW**************@TK2MSFTNGP05.phx.gbl...
Hi Everyone,

I'm having a problem trying to place text with in my custom buttons. The
problem is that I'm trying to display my text just as if it were a regular
'win' button, I have tried using Rectangle (which is good) & also by
inputting regular attributes. The thing is that, it is unknown how many
words will be displayed & breaks between the words, if there are any.at
runtime. I have tried developing the syntax to account for all
possibilities but it seems endless.

Does anyone have a solution to this problem of mine? I also have tried
surfing Bob Powell's site for info. My code is as follows. Thanks all in
advance.

MikeY

//------------------------------------------------------------

int Point_Width = 5;

int Point_Height = 5;

Font drawFont = new System.Drawing.Font("Tahoma", 8F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));

//Colour Of The Text

SolidBrush drawBrush = new SolidBrush(Color.Black);

//Converts Input Text To Upper Characters

string Input_Text = this.Text.ToUpper();

//Align Text To The Center Of The Button

StringFormat sf = new StringFormat();

sf.Alignment = StringAlignment.Center;

//Text Size

SizeF Text_Size = myGraphics.MeasureString(Input_Text, Font);

char[] separator = {' '};

string[] myWords;

myWords = Input_Text.Split(separator);

if(myWords.Length == 1)

{

Point_Height = 17;

}

else if(myWords.Length == 2)

{

Point_Height = 10;

}

else if(myWords.Length == 3)

{

Point_Height = 5;

}

myGraphics.DrawString(Input_Text, drawFont, drawBrush, new Rectangle(new
Point (Point_Width,Point_Height), new Size(ClientRectangle.Width - 5,
ClientRectangle.Height -5)), sf);

//Display Button In Parent Form

this.Region = new Region(myGraphicsPath);

drawBrush.Dispose();

myPen.Dispose();

myGraphicsPath.Dispose();

Sep 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.