Custom Buttons & Text Placement [C# Win]

M

MikeY

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top