Try a writing board with VB.NET (2)

zhaozj2021-02-11  200

All source code is downloaded here: http://www.up2e.com/resource.php

Try a writing board with VB.NET (2) --by zigz (Luhai) Luluhai@eastday.com

3) Hide of the status bar

That is to have a check button in the "View" menu. When checking = true, click on its status bar to hide, and then cancel hide.

Private sub mstatusbar_click (byvale as system.object, byval e as system.eventargs) Handles Mstatusbar.Click

IF mstatusbar.checked = true kil

Statusbar1.visible = false

MSTATUSBAR.CHECKED = FALSE

Else

Statusbar1.visible = true

MSTATUSBAR.CHECKED = TRUE

END IF

End Sub

4) Questions about font styles

I think this is the most difficult part of this program. In order to achieve this feature, I have answered many information, and I finally enable the font dialog setting, only the toolbar can implement several font styles and functions. Figure 3 font styles and "sample" in the picture above is bolding and bodied and downline, don't think that this function is very simple, because I found that if a word is bold, when I choose a bevel button I found that her original bold pattern disappeared, turned into only a slope pattern, that is, the style of the font could not be used, and later found a solution.

One of the "OR" is indeed critical, which has a decisive role. The key is not familiar with the grammatics of VB, and if it is a C language. Let's take a look at the code 'below this function is used to increase the style of the font, such as bold, underscore, etc.

Public Sub AddFontStyle (Byval RTB As RichtextBox, _

Byval style as system.drawing.fontstyle

'If the selected text length is greater than 0, a character will add a style.

'This is very necessary! Because the selected characters may contain a variety of styles,

'And our original interest is just to keep all the original styles, while adding the specified style

IF RTB.SerectionLength> 0 THEN

DIM SELSTART AS INTEGER = RTB.SELECTIONSTART

DIM SELLENGTH AS INTEGER = RTB.SerectionLENGTH

DIM Currfont as system.drawing.font

Dim currsty as system.drawing.fontstyle

DIM I as integer

For i = 0 to Sellength - 1

'Select characters

RTB.SELECT (SELSTART I, 1)

'Get the font of the selected character

Currfont = RTB.SelectionFont

'Get the current style while adding the specified style

Currstyle = currfont.style

Currstyle = Currstyle or Style

'Then make the characters have new fonts and new styles, which may have an exception.

'Because all fonts support all styles, so you can capture abnormalities.

Try

RTB.SelectionFont = New font (currfont.since, _currsty) catch exception

END TRY

NEXT

RTB.Select (SELSTART, SELLENGTH)

Else

RTB.SeLectionFont = New font (RTB.SelectionFont, _

RTB.SeLectionFont.style or Style

END IF

End Sub

Similarly, there is also the same problem in canceling the style, of course, the same solution

'The following function is used to remove the font styles specified by the user, such as bold, underscore, etc.

Public Sub RemoveFontStyle (Byval RTB As Richtextbox, _

Byval style as system.drawing.fontstyle

'If the length of the text is selected is greater than 0, one will remove the style.

'This is very necessary! Because there may be many different styles in the selected text, and our original meaning is

'Keep all the original style, except the style to be removed

IF RTB.SerectionLength> 0 THEN

DIM SELSTART AS INTEGER = RTB.SELECTIONSTART

DIM SELLENGTH AS INTEGER = RTB.SerectionLENGTH

DIM Currfont as system.drawing.font

Dim currsty as system.drawing.fontstyle

DIM I as integer

For i = 0 to Sellength - 1

'Choose a character

RTB.SELECT (SELSTART I, 1)

'Get the font of the selected character

Currfont = RTB.SelectionFont

'Get the style of the selected character, while removing the pattern removed

Currstyle = currfont.style

Currstyle = Currsty and Not Style

'Give these characters new fonts and patterns

RTB.SelectionFont = New font (Currfont.fontfamily, Currfont.size, _

Currstyle

NEXT

'Keep original selection

RTB.Select (SELSTART, SELLENGTH)

Else

RTB.SeLectionFont = New font (RTB.SelectionFont, _

RTB.SelectionFont.Style and not style

END IF

End Sub

There are also a few words about setting font size, font, etc., if you need, I can provide all source code files. Welcome to contact me. Luluhai@eastday.com is not complete ...

转载请注明原文地址:https://www.9cbs.com/read-3732.html

New Post(0)