[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9926
  • Last Modified:

VB.NET Making a new font Bold and italic

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
harveyball
Asked:
harveyball
  • 4
  • 4
  • 2
  • +3
1 Solution
 
ptakjaCommented:
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
 
ptakjaCommented:
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
 
DotNetLover_BaanCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
bramsquadCommented:
     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
 
DotNetLover_BaanCommented:
this is for regular...          Label1.Font = New Font(Label1.Font.FontFamily, Label1.Font.Size, FontStyle.Regular)
0
 
gregasmCommented:
"Incidentally, .NET isn't stupid, its object oriented."

BUAHAHAHA

0
 
Bob LearnedCommented:
Yes, stupid is only a matter of opinion and perspective.  *GRIN*

Bob
0
 
harveyballAuthor Commented:
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
 
ptakjaCommented:
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
 
harveyballAuthor Commented:
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
 
DotNetLover_BaanCommented:

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
 
ptakjaCommented:
Baan,

Your code would only allow ONE font attribute to be set at a time. ;-)
0
 
DotNetLover_BaanCommented:
ohhhhhhhhhhh..... damn... I got it....  thanks ptakja
-Baan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now