|
Hmmm... Interesting. Which message is it looking for?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
The message is EM_SETCHARFORMAT. I noticed that when you set the Font property for the RichTextBox this message is sent. So I looked for it when I set the SelectionFont property. Sure enough it was sent then as well. I looked for a difference and noticed the messages only differ by the wparam value. A value of 4 was being sent when you set the Font and a value of 1 was being sent when you set SelectionFont. So I figured why not change it and see what happens. I tried a 2 and then a 3. 3 seemed to fix the problem. Although I never fully tested the consequences so some thorough testing should be done.
|
|
|
|
|
I tried using the code to make a New control, but I get a squiggley under
Inherits RichTextBox with the message RichTextBox not defined.
I am also currently using an extended RichTextBoxPrintCtrl so ideally I would like to keep this control with what you have suggested placed in there, if that's possible?
|
|
|
|
|
Maybe try the full path "Inherits System.Windows.Forms.RichTextBox". The fix should work with your extended class. As long as it's a RichTextBox at the heart. All you should have to do is copy and paste the WndProc method.
|
|
|
|
|
I tried pasting the code into the RTB Class, which already has the Inherits RichTextBox
But still no luck
I have pasted all of the code for the RTB below.
<br />
Option Explicit On<br />
<br />
Imports System<br />
Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.Runtime.InteropServices<br />
Imports System.Drawing.Printing<br />
<br />
<br />
''' <summary><br />
''' The rich text box print control class was developed by Microsoft, information about<br />
''' this control can be found in your help files at: <br />
''' ms-help:
''' In general, their intent was to create a rich text box control with print capability<br />
''' embedded into the control.<br />
''' </summary><br />
''' <remarks>This control class replaces the use of the regular RichTextBox control; the<br />
''' purpose of this extension was specifically to facilitate printing the contents<br />
''' of a rich text box control.</remarks><br />
<br />
Public Class RichTextBoxPrintCtrl<br />
Inherits RichTextBox<br />
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)<br />
If m.Msg = &H444 AndAlso m.WParam.ToInt32 = 1 Then m.WParam = New System.IntPtr(3)<br />
MyBase.WndProc(m)<br />
End Sub<br />
' Convert the unit that is used by the .NET framework (1/100 inch) <br />
' and the unit that is used by Win32 API calls (twips 1/1440 inch)<br />
Private Const AnInch As Double = 14.4<br />
<br />
<StructLayout(LayoutKind.Sequential)> _<br />
Private Structure RECT<br />
Public Left As Integer<br />
Public Top As Integer<br />
Public Right As Integer<br />
Public Bottom As Integer<br />
End Structure<br />
<br />
<StructLayout(LayoutKind.Sequential)> _<br />
Private Structure CHARRANGE<br />
Public cpMin As Integer ' First character of range (0 for start of doc)<br />
Public cpMax As Integer ' Last character of range (-1 for end of doc)<br />
End Structure<br />
<br />
<StructLayout(LayoutKind.Sequential)> _<br />
Private Structure FORMATRANGE<br />
Public hdc As IntPtr ' Actual DC to draw on<br />
Public hdcTarget As IntPtr ' Target DC for determining text formatting<br />
Public rc As Rect ' Region of the DC to draw to (in twips)<br />
Public rcPage As Rect ' Region of the whole DC (page size) (in twips)<br />
Public chrg As CHARRANGE ' Range of text to draw (see above declaration)<br />
End Structure<br />
<br />
Private Const WM_USER As Integer = &H400<br />
Private Const EM_FORMATRANGE As Integer = WM_USER + 57<br />
<br />
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr<br />
<br />
' Render the contents of the RichTextBox for printing<br />
' Return the last character printed + 1 (printing start from this point for next page)<br />
Public Function Print(ByVal charFrom As Integer, ByVal charTo As Integer, ByVal e As PrintPageEventArgs) As Integer<br />
<br />
' Mark starting and ending character <br />
Dim cRange As CHARRANGE<br />
cRange.cpMin = charFrom<br />
cRange.cpMax = charTo<br />
<br />
' Calculate the area to render and print<br />
Dim rectToPrint As RECT<br />
rectToPrint.Top = e.MarginBounds.Top * AnInch<br />
rectToPrint.Bottom = e.MarginBounds.Bottom * AnInch<br />
rectToPrint.Left = e.MarginBounds.Left * AnInch<br />
rectToPrint.Right = e.MarginBounds.Right * AnInch<br />
<br />
' Calculate the size of the page<br />
Dim rectPage As RECT<br />
rectPage.Top = e.PageBounds.Top * AnInch<br />
rectPage.Bottom = e.PageBounds.Bottom * AnInch<br />
rectPage.Left = e.PageBounds.Left * AnInch<br />
rectPage.Right = e.PageBounds.Right * AnInch<br />
<br />
Dim hdc As IntPtr = e.Graphics.GetHdc()<br />
<br />
Dim fmtRange As FORMATRANGE<br />
fmtRange.chrg = cRange ' Indicate character from to character to <br />
fmtRange.hdc = hdc ' Use the same DC for measuring and rendering<br />
fmtRange.hdcTarget = hdc ' Point at printer hDC<br />
fmtRange.rc = rectToPrint ' Indicate the area on page to print<br />
fmtRange.rcPage = rectPage ' Indicate whole size of page<br />
<br />
Dim res As IntPtr = IntPtr.Zero<br />
<br />
Dim wparam As IntPtr = IntPtr.Zero<br />
wparam = New IntPtr(1)<br />
<br />
' Move the pointer to the FORMATRANGE structure in memory<br />
Dim lparam As IntPtr = IntPtr.Zero<br />
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange))<br />
Marshal.StructureToPtr(fmtRange, lparam, False)<br />
<br />
' Send the rendered data for printing <br />
res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam)<br />
<br />
' Free the block of memory allocated<br />
Marshal.FreeCoTaskMem(lparam)<br />
<br />
' Release the device context handle obtained by a previous call<br />
e.Graphics.ReleaseHdc(hdc)<br />
<br />
' Return last + 1 character printer<br />
Return res.ToInt32()<br />
End Function<br />
<br />
End Class<br />
<br />
|
|
|
|
|
So the code didn't change anything at all? What version of Visual Studio are you using? I'm using 2005 and that worked great for me. If we're using different versions of the .net framework then maybe our RTB's are also slightly different. Is the code even executing? Try breaking the if then statement up and putting a break point on the code that executes. Also add in a line that prints the message. You can output it however you like I usually just send it to the console or debug window.
If m.Msg = &H444 AndAlso m.WParam.ToInt32 = 1 Then
console.writeline(m.tostring)
m.WParam = New System.IntPtr(3)
End IF This code should execute whenever the font or selectionfont is changed. If it doesn't execute then that's good to know and clearly something is different, and if it does execute maybe the message is slightly different. If it does execute then post the output and we can see if there is a solution that will work for you. Please post the message you get when you change the font property as well as when you change the selectionfont property.
|
|
|
|
|
Hi TwoFace,
Thanks for the help so far. I'm using VB2005 Express Edition.
I tried the code in the RichTextBoxPrintControl.vb form but nothing happens, doesn't even get executed.
So I then tried it in the ctlFontCombo.vb form this is a control for the dropdown ComboBox problem now is the message
'Inherits' can only appear once within a 'Class' statment and can only specify one class.
I removed the Inherits RichTextBox and it kept looping with the message below.
<br />
msg=0x81 (WM_NCCREATE) hwnd=0x40670 wparam=0x0 lparam=0x3addbf4 result=0x0<br />
msg=0x7c (WM_STYLECHANGING) hwnd=0x40670 wparam=0xfffffffffffffff0 lparam=0x3add300 result=0x0<br />
msg=0x7d (WM_STYLECHANGED) hwnd=0x40670 wparam=0xfffffffffffffff0 lparam=0x3add300 result=0x0<br />
msg=0x7c (WM_STYLECHANGING) hwnd=0x40670 wparam=0xffffffffffffffec lparam=0x3add300 result=0x0<br />
msg=0x7d (WM_STYLECHANGED) hwnd=0x40670 wparam=0xffffffffffffffec lparam=0x3add300 result=0x0
If it would help I could zip it all up so that you can see the full program my email is spare.box@(noSpam)virgin.net just remove the (noSpam) bit and let me know I will then send you a link to where it can be downloaded.
Cheers
Graham
|
|
|
|
|
My guess is at the moment we aren't on the same page. You said you changed the font...how? Please provide that code so I can see exactly how your doing it. Also any other snippets of code that you think might help. The RichTextBox class you provided works for me. I feel I may not have an accurate picture of what your doing or how your doing it. Please post the code and elaborate/clarify as best you can. Maybe we can figure it out here. If you'd like you can email me your code so I can get a better look at everything. Please send it to KVSJOVEJASMI@spammotel.com. Or if you prefer just email me a link to where I can get it. If you really want to avoid spam check out spammotel.com It's a free simple service I discovered a few years ago. I can definitly vouch for it.
|
|
|
|
|
Thanks for the info, I have now signed up to SpamMotel and will tell other sabout it as well.
|
|
|
|
|
You had me spooked there! It appeared NO messages were being recieved by the richtextbox. I was so confused. Then I noticed it...rtbText is a ExtendedRichTextBox.RichTextBoxPrintCtr. You made a dll. You need to change the code and recompile the dll. I made the change and it worked. Nice program by the way!
|
|
|
|
|
You made a dll
Well no actually it was one that I downloaded from one of the many VB sites.
You need to change the code and recompile the dll.
How is this done? I changed the code and did a rebuild but still nothing happens, but as you did get it to work it's obviously something that I'm not doing, like I said I only downloaded the dll I have not had a lot of dll experience. Using them yes, creating and building them no, maybe I should have a go when this current project is finished.
|
|
|
|
|
Oh, I see. Getting it to work isn't a big deal. I just assumed you had created the dll. What you want to do then is remove rtbText from your application. That control is using the dll which your not going to modify so just remove it. The RichTextBoxPrintCtrl class on your form should appear as a usable control in the toolbox. When I extend a control like that it usually appears under a tab with the name of my application followed by components. For your app I can see the control under "QuickWord Components" which appears at the top of the toolbox. Hopefully you can see the control there. If so just drag it onto your form and rename it to rtbText. Everything should work as though nothing had changed. You may actually have two RichTextBoxPrintCtrl available. So you'll have to make sure you get the right one. Just drop either one onto your form and test it. One should work, the other won't. The other way to make absolutly sure you've got the right control is to add this line to the wndproc method you added to your class.
console.WriteLine(m.ToString) If your using the right control you should see alot of messages in the console window.
|
|
|
|
|
That’s done it
I never thought that after I altered the dll to then reintroduce it on to the form.(It’s always the Obvious!)
Thanks for all your help, understanding and patience, I think it’s fair to say that I’ve learned quite a lot from this thread and I hope others do too.
|
|
|
|
|
i wanna include calculator in one of the button event of VB.net application
but i dnt knw that can v interface our appliaction to OS or not...
please help.
|
|
|
|
|
I can't understand your question, but from what I'm guessing, you want to either write your own calculator app, which isn't that hard, or you can launch the Windows Calculator app using the Process class.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
its like i wanna incluede calculator given in windows to my form....
so that whenevr user need its he can get it by simply clickin it..
so that whenevr i click an event of form calculator get open...
can u tell me the procedure of incluiding through process class??
can u meet me online....
my yahoo id is cool_mani_n@yahoo.co.in
-- modified at 14:28 Friday 23rd February, 2007
|
|
|
|
|
manni_n wrote: can u meet me online....
my yahoo id is cool_mani_n@yahoo.co.in
Nope. And noone here will do that. Everything is kept in the forums so other people can learn from it.
manni_n wrote: its like i wanna incluede calculator given in windows to my form....
It's MUCH easier to just launch it and not make it part of your form. If you make it part of your form, just like a textbox or button, the user can move the calculator around your form, and you have no control over it.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
and hw that can be launched...?
|
|
|
|
|
Process.Start. As you were told. If you are unable to research how to call a method when you've been told what it is, you need to turn off your computer, and find a job in the fast food industry.
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 )
|
|
|
|
|
thanks for yr concerned suggestion man...
dnt worry even also there i'll make software for them in dot net only.
|
|
|
|
|
if u want that open windows calculatar, when u click a button. tn use this code
on button click event
Dim Calculator As String
Calculator = Shell("calc.exe", AppWinStyle.NormalFocus)
Thanks & Regards
Form :-
Vikash Yadav
|
|
|
|
|
yeah its workin man....
thanks for your help....
wid regards.....
|
|
|
|
|
we the facility to convert vb into vb.net..
can we do the same from vb.net to vb
please explain the procedure if yes.....
|
|
|
|
|
Why on earth would you want to do such a thing? It can be done. There is no tool in existance that will do it for you though. You have to convert all the code by hand.
You'll also have a problem with all of the .NET Framework classes that the VB.NET code uses since they won't exist in VB6 at all. You'll either have to recreate their functionality in VB6 code (LOTS of work there!), or you can write custom COM wrappers around the .NET Framework classes you need to use in the code.
But, in the second case, if you were to wrap the .NET classes in COM wrappers to call them in VB6, what's the point of even rewriting the code in VB6 in the first place?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello,
I am using Vb.NET
Does anyone have any idea why I am getting the following error at the line where it says: dataAdapter.Update(data, "Caller Records")
Error message is:
Incorrect syntax near 'Records'.
Here is the full code:
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Dim data As New DataSet
Dim dbConn As OleDb.OleDbConnection
Dim dataAdapter As OleDb.OleDbDataAdapter
Dim connectionString As String = "Provider=SQLNCLI;Server=A45292\SQLEXPRESS;DataBase=FSS;Trusted_Connection=Yes"
Dim sqlString As String = "SELECT * FROM [Caller Records] Where RecordNo =" & TextBox2.Text
dbConn = New OleDb.OleDbConnection(connectionString)
dataAdapter = New OleDb.OleDbDataAdapter(sqlString, dbConn)
dataAdapter.Fill(data, "Caller Records")
Dim tbl As DataTable
tbl = data.Tables("Caller Records")
Dim selectedRows() As DataRow
selectedRows = tbl.Select("RecordNo = " & TextBox2.Text)
If selectedRows.Length > 0 Then
selectedRows(0).Item("FirstName") = FirstNameTextBox.Text
selectedRows(0).Item("LastName") = LastNameTextBox.Text
selectedRows(0).Item("CallerPhone") = CallerPhoneTextBox.Text
selectedRows(0).Item("HospitalNumber") = TextBox1.Text
selectedRows(0).Item("Type") = TypeTextBox.Text
End If
Dim myBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(dataAdapter)
myBuilder.GetUpdateCommand()
dataAdapter.UpdateCommand = myBuilder.GetUpdateCommand()
dataAdapter.Update(data, "Caller Records")
MessageBox.Show("Database Is Updated")
dbConn.Close()
programmer
|
|
|
|