Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i am making a basic little text editor.

 

i want to allow the user to make the font bold and italics, or bold and underline at the same time.

 

when i set a FontStyle, it only alows me to set 1. ( bold, itlaic, underline ) and if i set 1, it sets everything else to regular.

 

how can i make a FontStyle both Bold and Italics without a dialog ?

  • *Experts*
Posted

Dim fs as FontStyle
fs = FontStyle.Bold Or FontStyle.Italic

Use the keyword Or to combine the values. You might also want to read up MSDN on how it works.

:)

Posted
Dim fs as FontStyle
fs = FontStyle.Bold Or FontStyle.Italic

Use the keyword Or to combine the values. You might also want to read up MSDN on how it works.

:)

 

Just curious why is it OR instead of AND ?

Debug me...
Posted

I have another question on the text editor issue.

The bold/italic/underline buttons are togglebuttons that can be combined. Now I've added three buttons for left, right and center alignment to my toolbar. These are togglebuttons that can only be selected exclusively. Is there some property I haven't found or do I have to code the behaviour myself?

Debug me...
Posted

AND would substract the flags in this case...

 

bitwise AND:

 

111000

AND

000111

->

000000

 

if you'd do a bitwise OR the result is the Addition of the flags:

 

111000

OR

000111

->

111111

 

Hope this helps!

 

Andreas

Posted

thanks for the info!

 

usually i can convert vb to c#, .. but i can not get that 'or' to work. here's the code i'm working with. just a simple toolbar click action with a bold and italic button. can someone help me just set one of these to both bold and italics with c# ?

System.Drawing.Font currentFont = this.rbFeatures.SelectionFont;
System.Drawing.FontStyle newFontStyle = currentFont.Style;

if(e.Button == tbbBold)
{
 if (this.rtbFeatures.SelectionFont.Bold == true)
 {
   newFontStyle = FontStyle.Regular;
 }
 else
 {
   newFontStyle = FontStyle.Bold;
 }
}
else if ( e.Button == tbbItalics )
{
 if (this.rtbFeatures.SelectionFont.Italic == true)
 {
   newFontStyle = FontStyle.Regular;
 }
 else
 {
   newFontStyle = FontStyle.Italic;
 }
}

  • Leaders
Posted
		if(e.Button==toolBarButton1)
		{
			int fStyle = (int)FontStyle.Bold + (int)FontStyle.Italic;
			FontStyle f=(FontStyle)fStyle;
			richTextBox1.SelectionFont=new Font(richTextBox1.Font.Name,richTextBox1.Font.Size,f);
		}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...