Solved

VB.NET Making a new font Bold and italic

Posted on 2004-08-24
13
9,496 Views
Last Modified: 2013-12-03
Hi

Im trying to make an ap with 3 checkboxes for bold italic and underline text

so which ever ones are seleced when you click a button a label will then be styled with that font

so if you check bold and italic then the font will be bold and italic style, and if you uncheck them all then the font will be just regular

In vb 6 this would have been easy by just setting the font properties, but as vb.net is crap it doesnt let u do this but forces u to make a new font and the style thing is stupid cos it does this or and thing, which doesnt do a damn thing except makes everything bold.

so does anyone know how to do this in vb.net

u would think this

           Dim MyFont As New System.Drawing.Font(textFamily.Text, mainTextSize, (System.Drawing.FontStyle.Bold And System.Drawing.FontStyle.Italic And System.Drawing.FontStyle.Underline))


would give u a bold, italic and underlined font but oh no its just bold nothing else

i just want to be able to say if boldbox.checked or italicbox.checked or underlinebox.checked then make a font with these styles

hope that all makes some sense, any help would be great!

Thanks

Harvey
0
Comment
Question by:harveyball
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +3
13 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 11885394
Try using OR instead of AND when combining bits in a bitfield.

Dim MyFont As New System.Drawing.Font(textFamily.Text, mainTextSize, (System.Drawing.FontStyle.Bold OR System.Drawing.FontStyle.Italic OR System.Drawing.FontStyle.Underline))
0
 
LVL 14

Expert Comment

by:ptakja
ID: 11885410
Incidentally, .NET isn't stupid, its object oriented.  VB6 did not fully support object oriented programming.  The learning curve is high, but once you get the hang of it, I think you will see the benefits of programming in a fully supported object oriented language.
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11885430
Hi there...

        Label1.Font = New Font(Label1.Font.FontFamily, Label1.Font.Size, FontStyle.Bold)
        Label1.Font = New Font(Label1.Font.FontFamily, Label1.Font.Size, FontStyle.Underline)
        Label1.Font = New Font(Label1.Font.FontFamily, Label1.Font.Size, FontStyle.Italic)

-Baan
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 8

Expert Comment

by:bramsquad
ID: 11885438
     i took this snippet from some code i have for a combo box.....note the or statements, instead of the and statements  

      Me.cboSource.Font = New System.Drawing.Font("Tahoma", 9.75!, CType((( _
           System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic) _
           Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))

~b
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11885472
this is for regular...          Label1.Font = New Font(Label1.Font.FontFamily, Label1.Font.Size, FontStyle.Regular)
0
 
LVL 8

Expert Comment

by:gregasm
ID: 11885585
"Incidentally, .NET isn't stupid, its object oriented."

BUAHAHAHA

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11885630
Yes, stupid is only a matter of opinion and perspective.  *GRIN*

Bob
0
 

Author Comment

by:harveyball
ID: 11885773
so how do i make a simple line from 3 checkboxes to determine what style i want

so something like

new font(myfamily, mysize,(isbold.checked or isitalic.checked or isunder.checked))

something like that
0
 
LVL 14

Accepted Solution

by:
ptakja earned 125 total points
ID: 11885834
no, something like this:

Dim FStyle As FontStyle

If isBold.Checked Then
    FStyle = FontStyle.Bold
End If

If isItalic.Checked Then
  FStyle = FStyle OR FontStyle.Italic
End IF

If IsUnder.Checked Then
  FStyle = FStyle OR FontStyle.Underline
End If

new font(myfamily, mysize, FStyle)
0
 

Author Comment

by:harveyball
ID: 11885962
thank you very much (i still dont like vb! :p im a delphi and java programmer by nature, not used to all this microsoft tat :p)
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11886000

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim MyFontStyle As FontStyle
        MyFontStyle = FontStyle.Regular
        If ChkBox_Bold.Checked Then
            MyFontStyle = FontStyle.Bold
        End If
        If ChkBox_Italic.Checked Then
            MyFontStyle = FontStyle.Italic
        End If
        If ChkBox_UnderLine.Checked Then
            MyFontStyle = FontStyle.Underline
        End If
        Label1.Font = New Font(Label1.Font.FontFamily, Label1.Font.Size, MyFontStyle)
End Sub

-Baan
0
 
LVL 14

Expert Comment

by:ptakja
ID: 11886030
Baan,

Your code would only allow ONE font attribute to be set at a time. ;-)
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11886069
ohhhhhhhhhhh..... damn... I got it....  thanks ptakja
-Baan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question