|
I have tried that, unfortunitely I get the same result.
Mike
|
|
|
|
|
Is there a way I can change only the font size of the contents in a Rich Text box? I've tried using
MainTxt.Font = New Font(MainTxt.Font.Name, 12) but that still removes any bold, italics, etc.
Any thoughts would be greatly appreciated.
Thanks for your time,
Brian
|
|
|
|
|
If you go in to the design view of the form and go in to the property of the rich text box. You can set the font size under Font property. Or you can set the font size in the load method of that form. by:
RichTextBox1.Font = New Font(RichTextBox1.Font.Name, 5)
---------------------------------
There is life outside coding.
|
|
|
|
|
The problem with that is the contents of the Rich Text Box, an rtf file, is loaded and reloaded several times throughout the program.
|
|
|
|
|
Maybe you can first select all the text, and then change the selectionfont.
'Dunno if this works:
'select all text
rtb.SelectionText = rtb.Text
'change font (only size so use old font)
'i don't know what happens if there are different fonts involved in the selection..
rtb.SelectionFont = New Font(rtb.SelectionFont, 12.0!)
'deselect the text
rtb.SelectionLength = 0
You could also look at the RichTextBoxExtended article.
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
Same thing, lost the bold and styles.
|
|
|
|
|
Using just the standard RTB control, you'll have to go through each part of the text and see if the font changes from the previous font style. Say you have a length of text and only the middle 1/3 of the text is in a different style. You'd have to do 3 font changes. Select the first part of the text, change it's font size by creating a new font using the name and styles of the existing font. Then find the next section of text based on its Font, change it's font, then find the last section of text and do the same.
Not very efficient, huh? Your only alternative is to replace the RTB with an extended version of the control that offers, well, more control over the editing capability of the text.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Crap.
You could do it one char at a time, but i think it's going to be slooooooow.
I'm going to bed now, good luck with it
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
Yeah it is!!
The way to do it, without the RTB is to represent the Text and formatting in a data structure behind the scenes, then render the visible version using that data. It then makes changing the font, or pieces of it, in sections very easy since you're not hunting for the changes in the font through out the text. The code would already know where to make the changes.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Now how would this translate into some hard code?
|
|
|
|
|
I haven't written anything like that. I just have a couple theories in my head about how I would approach the problem.
Storing the text seperate from the formatting gives you quick access to the formatting itself. Pointers between text segments and existing formatting objects in a collection would allow for reuse of the same formatting object to control the formatting of several segments of text.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Since quite sometime I am trying to figure out how to change backcolor of a particular column in datagridview.
CellPainting event does that but I do not want to use, is there any property available, which can be used easily?
Please suggest, Thanks in advance.
Thanks,
RajKat
|
|
|
|
|
In your column's DefaultCellStyle property, you can change the BackColor. For example:
' Somewhere in your code to setup your columns:
'
Dim newCol As New DataGridViewTextBoxColumn
With newCol
.DataPropertyName = "databaseTableColumnName"
.HeaderText = "My Column Header"
.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.DefaultCellStyle.BackColor = Color.Blue
End With
DataGridView1.Columns.Add(newCol)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hey Dave,
Thanks for the solution, I was really looking for it.
Can you also tell me how to change the backcolor of just one cell of a datagridview?
I do not know what the problem is but
datagridview.rows(0).cells(0).style.backcolor=color.gray
is not working for me.
If any alternative or solution is there then please let me know.
Thanks,
RajKat
|
|
|
|
|
That code should work fine, so long as the DGV is filled with data already.
RoundsGridView.Rows(0).Cells(0).Style.BackColor = Color.BurlyWood
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have 2 DataGridView and I need them to scroll together. The first DataGridView has Scrollbars set to none and the second DataGridView is only displaying the Vertical scrollbar. I need the Sync. the second DataGridView's vertical scrollbar to move the first DataGridView's vertical position.
Private Sub _Scrolling(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs)<br />
Dim g As DataGridView = CType(Me.MainTabControl.Controls.Find("Employee_times", True)(0), DataGridView)<br />
' need help tranfering the event to the first DataGridView<br />
End Sub
Thanks.
|
|
|
|
|
Well, there's an easy way and a hard way. We'll try the easy way first:
The easy way is to put both DGV's in a Panel control and turn scrolling on in the panel. Don't turn on scrolling in the DGV's and don't worry about how big they DGV get. Just let them grow as far as they want in the vertical direction. The panel will then take care of the scrolling for you.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How simple was that. LOL I ended up with a work around using the..
gTime.SetBounds(0, (-gEmployee.VerticalScrollingOffset) + 11, gTime.Size.Width, gTime.Size.Height)
Thanks for the help. I've been wanting to contribute to the site with an article of some sort. So, I'm thinking of using parts of my current project with the multiple datagridviews and runtime creation of them and linking. As my first attempt at an article on the site.
Thanks again.
|
|
|
|
|
Hello,
Herebelow my need:
I want application1 is notified when the user click on the ok button of application2.
I don't know how to code application1, please help me.
sign
|
|
|
|
|
You would normally use .NET Remoting, but something tells me you don't have any control over application2. Meaning, you didn't write application2 and you don't have the source code for it - Correct?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I want an API in windows that change My file Type.
|
|
|
|
|
No such thing. Perhaps if you gave a detailed description of what you're doing, we can come up with a solution.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Does anyone have sample VB 2005 code that has a Treeview control that can sort nodes alphabetically?
I've been searching the internet for days, and I can't see any code that implements sorting.
I want to avoid putting all elements into a listview, sorting that, then adding items to the treeview from the listview because there will be thousands of items in each branch and performance could be seriously affected.
I know there's a TreeViewNodeSorter Method in the Treeview, but I can't figure out how to use it.
Any help appreciated.
Iain
|
|
|
|
|
The existing TreeView already supports custom sorting, so it's no wonder you can't find a replacement control.
The TreeViewNodeSorter is not a method, but a property. It's expecting an instance of a class that you write that implements the IComparer interface. All you're doing is supplying a method to compare two arguments (Nodes) that the Treeview wants you to compare, comparing them yourself, returning a value (-1, 0, or 1) that says in which order the first and second arguments relate to each other. For example:
Imports System.Collections
Public Class MyNodeSorter
Implements IComparer
<font color=green>' You MUST supply the code for the Compare method using this exact function header!!</font>
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
<font color=green>' All you do is compare the objects you get (they should always be TreeNodes).
' First, cast the Objects you get to TreeNodes.</font>
Dim x As TreeNode = CType(x, TreeNode)
Dim y As TreeNode = CType(y, TreeNode)
<font color=green>' Then compare the Text properties of each node. Since the String class already
' supplies a Comparer implementation that works on strings (duh!), just use that
' to do the work for you and return the value that it returns.</font>
Return String.Compare(x.Text, y.Text)
End Function
End Class
Docs on String.Compare(string, string) [^]
So, all you have to do is create an instance of this class and pass it to the TreeViewNodeSorter property, say in Form_Load, or in a "Sort" button click event handler:
TreeView1.TreeViewNodeSorter = New MyNodeSorter()
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
That's a clear explanation, I'll try it out. I'm new to VB 2005 - I never realised it would be so complicated. I thought the Treeview would have built in sort functionality; it seems very fundamental.
Thanks a lot for replying, much appreciated.
Iain
|
|
|
|