|
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
|
|
|
|
|
Let me explain how I’m doing it. I first initialize the assembly which contains Class B from Class A:
Sub b1()
The sub in the assembly:
Class B
Dim host as object
Sub b1(byval host as object)
Me.host = host
End sub
End Class
Then I call sub C1 which is in class C in the main:
host.C1()
Maybe this isn’t right.
|
|
|
|
|
How does class C call class B ? If it has an instance of B, then it won't be disposed. If it's a member of the main form, it shouldn't be disposed.
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 )
|
|
|
|
|
Class C is not in the main form... it's in a secondary form in the main .exe
I first initialize the assembly (which contains Class B) from Class A:
Sub b1()
This is Class B with its initializing sub:
Class B
Dim host as object
Sub b1(byval host as object)
Me.host = host
End sub
End Class
Then I call sub C1 which is in class C in the main .exe
host.C1()
Maybe this isn’t right, but I'm not sure what's wrong
thanks
|
|
|
|
|
This looks convoluted. Passing objects like this is always bad, you should use delegates.
Looks like the assembly is not a member variable, that's the cause of your main problem.
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 )
|
|
|
|
|
I have a form with a datagrid, a textbox and 3 buttons.
BtnAdd - Adds a new event to the database
BtnSave - Saves to the database
BtnUpdate - Refreshes it and shows the updated version in the datagrid
My table only has an ID number and name - type Number and Text, but it wont write to the database for me, can someone show me way to do this please??
|
|
|
|
|
I'm trying to write some code that creates a picture box at a certain location when a user clicks a button. I am using this statement to initialize the picturebox:
Dim blip As Bitmap
blip = New Bitmap(filename of bitmap goes here)
Dim blipcase As New PictureBox
blipcase.Image = blip
and this statement to place the picturebox:
Dim Theta As Double = (Point.Y * PI) / 180
Dim location As New Point
location.X = (225 + ((Cos(Theta) * (30 * Point.X)) - 5))
location.Y = (225 + ((Sin(Theta) * (30 * Point.X)) - 5))
blipcase.Location = location
(Point is a system.drawing.point that contains the polar coordinates of the point)
Now, during a break in the program, I can see that location contains the right coordinates. However, I cannot get the picturebox to appear. So I do not think it is the location part that is wrong, but the initialization that is wrong. Can anyone else see something that I might be missing?
|
|
|
|
|