|
There are no other options, sorry. How does a control Id go into a connection string ?
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 )
|
|
|
|
|
common man there mst be some logic...
any other logic u suggest..
|
|
|
|
|
You're right. There's a way to do this, and I'm keeping it a secret from you.
OR, if you have 200 labels and you want to data bind them, then you need to write the code to do it yourself, or come up with a solution that involves iterating over the controls collection. If you answered my question, I may be able to help more. How is a connection string going to take a control Id ?
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 )
|
|
|
|
|
If I understand what you're doing, you should not be using a bunch of labels, textboxs, and checkbox's. Your approach requires you to write lots more code than is necessary. This problem is more appropriately handled by a bound DataGridView.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi Again,
How do I get it so that when the caret is on a normal line the formatting buttons are false, if I place it on a bold piece of text the Bold button is true etc like word does?
|
|
|
|
|
What control are you using ?
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 )
|
|
|
|
|
Sorry, always forget to mention that
VB2005 Express Edition
|
|
|
|
|
No, what control are you using, that shows bold text and has a caret. Is it the rich text box ?
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 )
|
|
|
|
|
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
???
|
|
|
|