|
Yes it's a RTB
|
|
|
|
|
Here is one possible idea. What I did was stored the selection font of the richtextbox. In the selectionchanged event I compared the selectionfont with the last font. If they are different you could update your controls to reflect the new font. The same concept could be applied to color as well.
Dim lastFont As Font = Nothing
Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.SelectionChanged
If (lastFont Is Nothing) OrElse (Not lastFont.Equals(RichTextBox1.SelectionFont)) Then
'The font is different so reflect changes
'Update lastFont to current font
lastFont = RichTextBox1.SelectionFont
'Testing purposes
Console.WriteLine(RichTextBox1.SelectionFont.ToString)
End If
End Sub
|
|
|
|
|
Thanks TF
Will have a go at this tomorrow and let you know how I get on.
BTW
Love that Console.Writeline idea, meant to say last time, it doesn't half go a long way to solving problems.
Cheers
Graham
|
|
|
|
|
TF, I like the way that works but it's not quite what I'm after.
What I am trying for is, if I have two lines of text, the first is Bold/Italic the second is Regular.
If I place the caret on Line 1 then the Bold and Italic Toolbar items are Selected(True), if I then place it on Line 2 the Bold and Italic Toolbar items are Deselected(False)
Basically where ever the caret is it will tell me what fontstyle it is on by switching on or off the highlighting on the fontstyle buttons on the Toolbar.
I think this may be a tall order but it would be great if it can be done.
Thanks
Graham
|
|
|
|
|
Not that tall of an order I am 99.99% sure I know what your after and the start I gave you will get you there. What I did was looked for a change in the selectionfont (aka. Where the caret is). If the caret goes from bold text to regular text the if statement will evaluate to true and the code inside will execute. All you need to do is look at the current font and update your controls as needed. Here is an example using your programs code
Dim m_LastFont As Font = Nothing
Private Sub rtbText_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbText.SelectionChanged
'Has font changed since last position?
If m_LastFont Is Nothing OrElse Not m_LastFont.Equals(rtbText.SelectionFont) Then
'Yes. Update GUI to reflect it
'Set last font to new font
m_LastFont = rtbText.SelectionFont
'If Bold button doesn't reflect current state change it
If tlbBold.Checked <> m_LastFont.Bold Then
tlbBold.Checked = m_LastFont.Bold
Bold = m_LastFont.Bold
End If
'If Italic button doesn't reflect current state change it
If tlbItalic.Checked <> m_LastFont.Italic Then
tlbItalic.Checked = m_LastFont.Italic
Italic = m_LastFont.Italic
End If
End If
End Sub
The font object has everything you need to know, except color, but the same principles can be applied there as well. I hope that clears things up. Assuming I understand what you want, which I think I do, this is your solution. Or at least the only one I could come up with
|
|
|
|
|
TF,
This is so close it's frustrating!
It works as you would expect, you place the caret over a section of Bold text and the tlbBold button Lights up, place it over Underline text and tlbBold is deselected and tlbUnderline is selected.
Sorted! Well not quite.
So what's not working? well try selecting some text, click one of the Fontstyle buttons, then move to another section of regular text and the Fontstyle is still selected.
Any Ideas?
|
|
|
|
|
Nice find I hadn't noticed that bug. The problem was when the font style was changed by the user m_LastFont never got updated. So if you then move the caret to a location that matches the original text you changed, the code thinks the new locations font style still matches the last location. The simple fix is update m_LastFont in your 'style' method to reflect the selectionfont. I just added the code 'm_LastFont = rtbText.SelectionFont' to the very end of the method and it seems to have fixed that bug. Hopefully there are no more surprises.
|
|
|
|
|
No Surprises, it just doesn't work for me.( It's Probabaly me )
Below is how I have it layed out, I've removed Italic, Underline and Strikethrough. to keep it concise.
Private Sub rtbText_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbText.SelectionChanged
'Has font changed since last position?
If m_LastFont Is Nothing OrElse Not m_LastFont.Equals(rtbText.SelectionFont) Then
'Yes. Update GUI to reflect it
'Set last font to new font
m_LastFont = rtbText.SelectionFont
'If Bold button doesn't reflect current state change it
If tlbBold.Checked <> m_LastFont.Bold Then
tlbBold.Checked = m_LastFont.Bold
Bold = m_LastFont.Bold
End If
End If
'Set last font to new font
m_LastFont = rtbText.SelectionFont
End Sub
Clever Knows the Answers,
Wise knows where to find them.
|
|
|
|
|
I think I wasn't clear. The last line in code you posted for selectionChanged event is m_LastFont = rtbText.SelectionFont. That line was meant to go in the 'Style' method. The problem was m_LastFont should get updated to reflect the current font whenever the user makes a change. Right now that's not happening which is why the bug occurs.
|
|
|
|
|
TF, you were more than clear, it was me who misunderstood.
Thanks, not just for the answer but for the excellent explanations and detailed examples.
Also thanks for other advice and help too, if you still have the program please be critical and if something needs to be improved, added or removed please let me know, or just go ahead and do it if you wish.
eg; to open a Word.doc I need to first open Word which is a bit of a pain but I can see no other way around it, and what if the user doesn't have Word installed but someone has sent them a word document by email?
Anyway, Thanks again for everything.
Graham
|
|
|
|
|
I think you can add a reference to microsofts word library and use that to read and convert .doc files. I found this example. http://www.codeproject.com/csharp/convertdocintootherformat.asp[^]It's written in C# but it should be understandable. On my machine I can add a reference to Microsoft Office 11.0 word library. The example references 10.0 and claims there is a word namespace. However, I can't seem to find a word namespace or anything else that appears usefull. I'm sure I'm just missing something. Anyway it's a a start.
|
|
|
|
|
Thanks for the link TF
Will take a look tomorrow.
-- modified at 18:00 Wednesday 28th February, 2007
Couldn't wait
Here's what I have now, but still not working
Case "doc"
'Open WOrd
Dim newApp As Word.Application = New Word.Application
'Give it the file to open
Dim Source As Object = (OFD.FileName)
Dim Unknown As Object = Type.Missing
newApp.Documents.Open(Source, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown)
'Select it all
Source.Select()
'Send it to the clipboard
Clipboard.SetDataObject(Source)
'Shut it down
newApp.Quit(Unknown, Unknown, Unknown)
'Add code here to paste it into my RTB
End Select
|
|
|
|
|
How do i make print text aligned to the centre on a page,
i have tried font.style, font. everything and cant find it!:
ive also tried adding this above: txtPrint.TextAlign = HorizontalAlignment.Center
The code i am working with is:
ev.Graphics.DrawString(txtPrint.Text, New Font("Century Gothic", 30, FontStyle.Bold), brushes.Black, 120, 120)
|
|
|
|
|
Use the MeasureString to get the width and height of the string and then calculate the center of the control or window to position your text.
Ex.
The Window's Width / 2 - TheFontWidth / 2 for the X cordinate
AND
The Window's Height / 2 - TheFontHeight / 2 for the Y cordinate
I think you can use the TextRenderer Class to to perform some more advanced drawing even in VB.NET
|
|
|
|
|
I have this code to print some text:
---
Private Sub frmPrint_Load...
txtPrint.Text = strName & ", You Got " & intPerc & "Completed on " & Date.Today
Try
Dim printdoc As New PrintDocument
AddHandler printdoc.PrintPage, AddressOf Me.printtext
printdoc.Print()
Catch ex As Exception
MessageBox.Show("There is a problem printing, please check with your teacher", _
ex.ToString())
End Try
MsgBox("Your certificate has been sent to the printer")
Me.Close()
frmResultHigh.Show()
End Sub
---
Private Sub printtext...
ev.Graphics.DrawString(txtPrin... New Font("Century Gothic", 24, FontStyle.Bold), Brushes.Black, 120, 120)
ev.HasMorePages = False
End Sub
---
Is there any way to make the lines of text on different lines on the printout, as obviously it all comes out on the same line at the moment, and is there any way to insert a pic after the text e.g.
---
Well Done
Name
Score
PICTURE
----
Cheers
|
|
|
|
|
Just add new line characters in the string where you want lines to be created. If you adding the text to a textbox it needs to have multiline set. txtPrint.text = "Line 1" & vbcrlf & "Line 2". This should create text on two different lines and drawstring should render them that way as well.
|
|
|
|
|
Cheers mate, i knew it would be something like that.
While im at it, is there any way to do 2 lines spaces without putting this:
& vbCrLf & vbCrLf
???
|
|
|
|
|
Yes, I think you have two options. "some text" & new string(vbcrlf,2) is the first. Not any better though, actually worse or create a function that wraps that up nicely for you.
Private Function newline(ByVal count As Integer) As String
Return New String(vbCrLf, count)
End Function
Now you can use: "some text" & newline(2)
|
|
|
|
|
Nice one.
One more question, last one i promise, in this code, how do i make it align to the centre, i have tried font.style, font. everything and cant find it!:
ive also tried adding this above: txtPrint.TextAlign = HorizontalAlignment.Center
ev.Graphics.DrawString(txtPrint.Text, New Font("Century Gothic", 30, FontStyle.Bold), brushes.Black, 120, 120)
|
|
|
|
|
Sorry, I'm not help there. You may want to start a new thread for that.
|
|
|
|
|
|
Hello,
I am binding a bindingsource to a datagridview and I have set the bindingsource to filter based on conditions.
However, I think that the criteria i have is too complex to put in the filter.
Is there an easier method to use.
I will try my best to explain the criteria:
AssemblyID, category, Type
Type (components, equipment, software)
Category - software (Office, DB, Anti-virus)
Category - components(memory, processor, input)
Category - equipment(printers, display, keyboard)
For example the customer could select from some combo boxes the category that want to display for that type.
I have tried doing something with the string.format e.g.
[code]
dim criteria as string = string.empty
criteria = string.format(AssemblyID = {0} AND Category = {1} AND Type = {2}",assemblyID, cboSoftware.text, cboType.text)
bindingsource.filter = criteria
dgvParts.datasource = bindingSource
[/code]
The above didn't work, so sure that filter can handle it.
Another problem I have is that i need to display many combinations for instance the user could select either software, components, or software. and the individual category for each one.
For example the user could select to find software and the category CPU, and also display components with category memory.
I think to solve this problem I would have to write many if statements, which I want to avoid doing. Is there a better more cleaner method to do this.
Many thanks for any suggestions.
Steve
|
|
|
|
|
Sorry for being dense, but could someone help?
Class A and Class B exist in the main (.exe) form.
Class A calls Class C from a .dll assembly
Class C needs to call Class B from the main form.
How can I be sure Class B remains in scope?
Thanks
|
|
|
|
|
For class C to call Class B at all, you need to hook them up via a delegate. That is your problem, nothing to do with scope.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Well, I can indeed call the Class B from Class C. However, eventually I get a message that Class B is disposed, which makes me think it has gone out of scope. I guess I'm missing something.
thanks
|
|
|
|
|