|
break_day wrote: but if the user clicks on "back" button ?
then, you can hide the frame2 and show the frame1. it's simple, isn't it?
|
|
|
|
|
but if change in form1 and hide it and show form2 and then show form1 the changes in form1 stay in it ?
|
|
|
|
|
You didn't get what he said. You don't use multiple forms. You use ONE form with multiple Panel controls on it, one on top of the other, with each Panel hosting the controls for one page of your "wizard".
|
|
|
|
|
Hi..
Im having an unusal problem when printing the string i pass printpage handler to the drawstring..
dim i as integer
dim stringtest as string
e.g. for i=0 to 8000
stringtest = stringtest & "TESTING" & vbnewline
next i
so the for loop will return 8000 TESTING each with a newline in it..
like :
TESTING
TESTING
TESTING....
(8000) total..
then i fire the printpage handler to measure and drawstring as needed...but i get a problem which is if i have 2000 or less it draws on the first and every page correctly but if i have more records in the string e.g. 5000... then it will print 10 blank pages and then show the rest of the records after that..
is there a real limit as too how much data one can store in a string at all ????????? is that the problem.. im really lost ..
any help would be appreciated..
hope i was clear
Regards
Robbo
modified on Wednesday, January 09, 2008 2:05:12 PM
|
|
|
|
|
Hi,
I suspect you are victim of some 16-bit limitation inside GDI+, your string probably has a
length of 72K chars.
Is it really necessary to create such a large string? Why would you have to print
everything using just one string? Why not use just "TESTING" inside a for loop?
|
|
|
|
|
Hi Luc
Thanks for your reply. so whats the best way to do this.. i know theres a better way to hold data and send to print etc ... but my programming skills arent there yet.. what do you propose i do.. is there a way i can check the string if it has reach max size and then create a new string etc..
i'd appreciate any advice you have ..ive literally googled everywhere and found example out of my scope when it comes to printing properly ... i know people use array's etc.. what do you propose and a helpful and not to heavy example would be much appreciated.
kind regards
Robbo
|
|
|
|
|
Hi,
DrawString takes many parameters, including the string text, and a pair of coordinates.
So why not organiza a loop (for, or while), and call DrawString many times, each time
with the same string (just "TESTING" would do), but with different coordinates?
The only drawbacks I can see is:
1. when you rely on DrawString to do word wrapping for you, then it needs all the wrappable
text at once; but for text lines of less than 10 chars each, this does not apply, does it?
2. when you rely on DrawString to do pagination for you, then it again needs all the
text at once; but that is not how pagination should be handled; you really need to
take care of coordinates yourself, and as soon as y reaches the bottom of the page,
tou should remember your position in the document, print the current page, and when
the next PrintPage event occurs, continue where you left off. Of course, if all your
pages are to be identical, you can just print N pages with L lines of text.
(You would need PrintPageEventArgs.HasMorePages no to ask for another page...)
BTW: if printing seems to complicate matters for you, you can do exactly the same
when painting text onto a Panel on screen...
modified on Thursday, January 10, 2008 10:37:38 AM
|
|
|
|
|
Hi again Luc..
I googled and got some info about how much data a string can handle.
here: Visual Basic Language Reference
String Data Type (Visual Basic)
Holds sequences of unsigned 16-bit (2-byte) code points ranging in value from 0 through 65535. Each code point, or character code, represents a single Unicode character. A string can contain from 0 to approximately 2 billion (2 ^ 31) Unicode characters.
so im guessing its not the size of the string thats the problem..
at the moment my code is simple and here it is... please take some time to check it out and really really tell me what if a string is more than 2000 records withit everything works well and if its more its create blank pages before adding reset of the records.
here's a snipped of some code im using broken down without sub's/functions and other declaration like fonts and rectangles etc.
dim largestring as string
dim i as integer
for i=0 to 8000
largestring = largestring & "testing" & vbnewline
next i
textsize = e.Graphics.MeasureString( _
largestring, datafont, _
New SizeF(Rect.Size.Width, DateRect.Size.Height), _
datastringformat, charsfitted, linesfilled)
If charsfitted > 0 Then
e.Graphics.DrawString(largestring, datafont, Brushes.Blue, DateRect, datastringformat)
End If
If charsfitted < (largestring.Length) Then
largestring = largestring. _
Substring(charsfitted)
e.HasMorePages = True
Else
e.HasMorePages = False
headingfont.Dispose()
subheadingsfont.Dispose()
the_font.Dispose()
e.Graphics.Dispose()
End If
what is it that i need to add to make it always accept and draw no matter what records are coming through in the string.
thanks alot champ.. i really appreciate your time so far.
|
|
|
|
|
Hi,
sorry I did not study your code in detail. Here are some comments:
1. please show multi-line code inside PRE tags, that way it is more readable.
2. I can not understand your code, it is incomplete, I see no method declaration, what
is Rect, where is charsFitted defined, etc.
3. you should Dispose() of things you created or ordered created, hence NOT e.Graphics
4. I don't really care about the upper limit of GDI+, I never had trouble with it,
but then I tend to do my own wrapping and pagination; you can have Graphics do wrapping
for a paragraph of text, pagination is a no no.
|
|
|
|
|
Cant thankyou enough for taking time to assist me.
here is my code
'***************** CODE START *******************************
Public Class Form1
dim charsfitted as integer = nothing
dim linesfilled as integer = nothing
dim largestring as string = nothing
Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
Dim sb As New System.Text.StringBuilder(largestring)
'if i put 2000 or less all is ok
'but if i put say as below which is 8000 then
'i getblank pages drawn 'first in preview
For i = 0 To 8000 but
'combine = combine & "10/01/08" '& vbCrLf 'i & vbCrLf
sb.Append("10/01/")
sb.Append(i)
sb.Append(vbNewLine)
Next i
largestring = sb.ToString
dlgPrintPreview.Document = PreparePrintDocument()
dlgPrintPreview.WindowState = FormWindowState.Maximized
dlgPrintPreview.PrintPreviewControl.Zoom = 1.2
dlgPrintPreview.ShowDialog()
End Sub
Private Function PreparePrintDocument() As PrintDocument
' Make the PrintDocument object.
Dim print_document As New PrintDocument
' Install BeginPrint, QueryPageSettings,
' PrintPage, and EndPrint event handlers.
AddHandler print_document.BeginPrint, AddressOf Print_BeginPrint
AddHandler print_document.QueryPageSettings, AddressOf Print_QueryPageSettings
AddHandler print_document.PrintPage, AddressOf Print_PrintPage
AddHandler print_document.EndPrint, AddressOf Print_EndPrint
' Return the object.
Return print_document
End Function
Private Sub Print_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
charsfitted = Nothing
linesfilled = Nothing
End Sub
Private Sub Print_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs)
End Sub
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim textsize As SizeF = SizeF.Empty
Dim Rect As New Rectangle(e.MarginBounds.Left, 180, 60, 880)
'*****************
'********FONTS
Dim datafont As Font
datafont = New Font("Times New Roman", 8, FontStyle.Regular, GraphicsUnit.Point)
Dim the_font As Font
the_font = New Font("Times New Roman", _
8, FontStyle.Regular, GraphicsUnit.Point)
'**************
'********STRING FORMATS
Dim datastringformat As New StringFormat
datastringformat.Alignment = StringAlignment.Center
datastringformat.LineAlignment = StringAlignment.Center
'measuring largestring to be printed in RECT colmn defined above
textsize = e.Graphics.MeasureString( _
largestring, datafont, _
New SizeF(Rect.Size.Width, Rect.Size.Height), _
datastringformat, charsfitted, linesfilled)
If charsfitted > 0 Then
Console.WriteLine("drawing more lines")
e.Graphics.DrawString(largestring, datafont, Brushes.Blue, Rect, datastringformat)
End If
If charsfitted < (largestring.Length) Then
largestring = largestring. _
Substring(charsfitted)
e.HasMorePages = True
Else
e.HasMorePages = False
headingfont.Dispose()
subheadingsfont.Dispose()
the_font.Dispose()
e.Graphics.Dispose() 'LUC SAID TO REMOVE THIS
End If
End sub
End Class
'************* CODE END *************************
I hope with your help ill work this out..
thanks a million.
|
|
|
|
|
Hi,
comments again:
1. you have choosen to ignore my first comment.
2. this time your code seems more complete, thanks.
3. e.Graphics.Dispose() 'LUC SAID TO REMOVE THIS
modifying/adding a comment does not fix a definite bug.
4. you have choosen to ignore my fourth comment; I can not help you further on this
since you are doing things I have not done and would not do, as I explained before.
5. I would not trust charsFitter since there are slight differences of opinion between
MeasureString and DrawString as you can tell by reading (in between the lines of) the documentation.
6. both MeasureString and DrawString take float SizeF/RectF so
Dim Rect As New Rectangle(e.MarginBounds.Left, 180, 60, 880) is a detour.
That's all.
|
|
|
|
|
vbbeg wrote: Visual Basic Language Reference
String Data Type (Visual Basic)
Holds sequences of unsigned 16-bit (2-byte) code points ranging in value from 0 through 65535. Each code point, or character code, represents a single Unicode character. A string can contain from 0 to approximately 2 billion (2 ^ 31) Unicode characters.
so im guessing its not the size of the string thats the problem..
Luc didn't say it was a problem with the String type. He said it was a possible problem with GDI+ handling strings that large.
|
|
|
|
|
vbbeg wrote: for i=0 to 8000
stringtest = stringtest & "TESTING" & vbnewline
next i
so the for loop will return 8000 TESTING each with a newline in it..
[nitpicking]
That will be 8001 TESTING each with a newline in it
[/nitpicking]
|
|
|
|
|
Hi Chandra..
do you have any ideas or recommendations to help me fix this..
Thanks
Robbo
|
|
|
|
|
Hi
I am not exactly sure, but shouldn't there be a way of printing a line at a time instead of a whole page?
Chandra
|
|
|
|
|
Hey again chand
ill take any suggestions you guys have. if you have any good examples i'd appreciate it.
Regards
Robbo
|
|
|
|
|
I seem to have a problem with setting up read/write access to registry entries created in HKEY_LOCAL_MACHINE. Let me give you a little history of what I’ve been doing.
Previously, on my windows applications, I have created the applications registry entries in HKEY_CURRENT_USER. This works fine except that the registry entries are created for every user who logs on to the PC and the correct values must be maintained for every user. In reality, I want a single set of registry entries that are machine dependent and used by anyone who logs onto the PC. Therefore, I want the entries in HKEY_LOCAL_MACHINE.
Here is the code I’ve used to create the HKEY_LOCAL_MACHINE entries...
<br />
<br />
Imports Microsoft.Win32<br />
<br />
Public Class frmMain<br />
<br />
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
' Set regKey to point to HKEY_LOCAL_MACHINE<br />
regKey = Registry.LocalMachine<br />
<br />
' Create regSubKey to point to HKEY_LOCAL_MACHINE\Software\Liebert\RegistryTest<br />
regSubKey = regKey.CreateSubKey("Software\Liebert\RegistryTest", RegistryKeyPermissionCheck.ReadWriteSubTree)<br />
<br />
' Check if registry value pName exists<br />
If (regSubKey.GetValue("pName") = "") Then<br />
<br />
' If pName does not exist... then create pName entry<br />
MsgBox("User must setup registry values!", MsgBoxStyle.OkOnly)<br />
<br />
regKey.CreateSubKey("Software\Liebert\RegistryTest", RegistryKeyPermissionCheck.ReadWriteSubTree)<br />
<br />
regSubKey.SetValue("pName", txtInitPortName.Text)<br />
regSubKey.SetValue("pBaud", txtInitPortBaud.Text)<br />
<br />
' Restart the application to make use of the new value pName<br />
MsgBox("Application will restart!", MsgBoxStyle.OkOnly)<br />
<br />
End<br />
<br />
Else ' pName exists already, use it !<br />
txtPortName.Text = regSubKey.GetValue("pName")<br />
txtPortBaud.Text = regSubKey.GetValue("pBaud")<br />
End If<br />
<br />
End Sub<br />
<br />
End Class<br />
<br />
The routine checks to see if the registry entries (“pName” specifically) exist and if they do not, the code will create them. Otherwise, it simply reads the values in. Everything appears to work properly. The first time I run the application without the registry entries existing, the entries are created and the user is forced to restart the application. The registry entries are then read properly.
The textboxes txtInitPortName.Text and txtInitPortBaud.Text contain the initial values to be written to the registry if the registry entries do not exist and the textboxes txtPortName.Text and txtPortBaud.Text will contain the values of the entries that are read if the registry entries do exist.
The problem is when I logoff of the PC and have someone else logon and then try to run the application. They immediately get an exception…
Access to the registry key "HKEY_LOCAL_MACHINE\Software\Liebert\RegistryTest" is denied
The new user is able to examine the registry entries, but is unable to change them.
I thought that when I create the subKey and set the access as follows…
regKey.CreateSubKey("Software\Liebert\RegistryTest", RegistryKeyPermissionCheck.ReadWriteSubTree)
...that this would give Read/Write access to all users… obviously it doesn’t and I am doing something wrong!
Any suggestions?
|
|
|
|
|
Member 4052115 wrote: I thought that when I create the subKey and set the access as follows…
regKey.CreateSubKey("Software\Liebert\RegistryTest", RegistryKeyPermissionCheck.ReadWriteSubTree)
...that this would give Read/Write access to all users…
Wrong. What you specified was your REQUEST for access to Read/Write the subtree. You didn't GRANT those permissions.
To normal users, the entire LOCAL_MACHINE key is read-only by default. To PowerUsers and Admins, it's Read/Write. During your applications installation, you can create the root key for your app, then you have to specifically grant Read/Write permissions to that key to whatever group you want, even the built-in Everyone group.
The CreateSubTree method has a third overload where you specify the key path, the requested access control (what you specified), and then a RegistrySecurity object that sets the security on the new key. But, normal users won't have access to create the key, nor set the access permissions. Only an Admin or PowerUser can create the root key and set access permissions.
Lookup "RegistrySecurity" in MSDN Help for examples on how to use it.
|
|
|
|
|
Dave,
Thanks for the response!
I think that what I need to do is (as an Admin user) is to install the application, start it and let the code see that the registry entries do not exist which will cause them to be created and then set them to the actual values I want for all users. Then when a normal user logs on and uses the PC, the registry entries will exist and he will be able to use the application. I can see that there are a few lines to tweak, but hopefully, not a big deal.
Thanks again for your help... it is most appreciated!
|
|
|
|
|
Dave,
After reading your response, I went back and did some digging and reqrote my code. However, i still seem to be having the same basic problem. I feel like I'm dancing all around the solution, but I just am not finding it. Here is the new code...
Imports Microsoft.Win32<br />
<br />
Public Class frmMain<br />
<br />
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
' Set regKey to point to HKEY_LOCAL_MACHINE<br />
regKey = Registry.LocalMachine<br />
' Create regSubKey to point to HKEY_LOCAL_MACHINE\Software\Liebert\RegistryTest<br />
regSubKey = regKey.OpenSubKey("Software\Liebert\RegistryTest", True)<br />
' Check if registry SubKey exists<br />
If (regSubKey Is Nothing) Then ' create SubKey<br />
regSubKey = regKey.CreateSubKey("Software\Liebert\RegistryTest")<br />
regSubKey.SetValue("pName", txtInitPortName.Text)<br />
regSubKey.SetValue("pBaud", txtInitPortBaud.Text)<br />
' Restart the application to make use of the new value pName<br />
MsgBox("Registry entries created!" & vbCrLf & "Application needs restarted!", MsgBoxStyle.OkOnly)<br />
End<br />
Else ' pName exists already, use it !<br />
txtPortName.Text = regSubKey.GetValue("pName")<br />
txtPortBaud.Text = regSubKey.GetValue("pBaud")<br />
End If<br />
<br />
End Sub<br />
<br />
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click<br />
<br />
End<br />
<br />
End Sub<br />
End Class
Again, I want my windows application to be run by myself the first time (as Admin on the machine). The application will check for the existence of the registry SubKey and if it does not exist (which it won't), it will create the SubKey (and also a couple of sample values just to see that it works. After creating the SubKey, the application will force a exit and I restart the application. This time, the registry SubKey exists and all the code does is to get the two values.
txtPortName.Text = regSubKey.GetValue("pName")
txtPortBaud.Text = regSubKey.GetValue("pBaud")
This all works fine for me as the user (Admin).
Now, I logoff and have someone else logon as a normal user. He then starts the application (the registry exists. He gets the following exception and does not read the values.
Note: I actually wanted to paste the messagebox in here for the exception, but couldn't figure out how.
Application attempted to perform an operation not allowed by the security policy. To grant this application the required permission, contact your system administrator, or use the Microsoft .NET Framework configuration tool.
If you click continue, the application will ignore the error and attampt to continue. If you click Quit, the application will quit immedately.
Requested registry access is not allowed.
In your previousmessage response, I thought that you implied that the normal user would be able to read the SubKey's values. Obviously, I'm missing something.
|
|
|
|
|
Your problem is that you're initially opening the subkey with write permissions by supplying the True argument to OpenSubKey :
' Create regSubKey to point to HKEY_LOCAL_MACHINE\Software\Liebert\RegistryTest
regSubKey = regKey.OpenSubKey("Software\Liebert\RegistryTest", True)
' Check if registry SubKey exists
If (regSubKey Is Nothing) Then ' create SubKey
and THEN you're checking to see if anything was returned. When a normal user runs that line of code, it'll fail because the user cannot open the key for write access.
Remove the True argument from that line and it'll run. Of course, you'll have to rewrite the code to find out if the key exists, then try and create the key path and values.
|
|
|
|
|
That makes sense! Hopefully, a little re-write and everything will be fine!
Thanks for all your help Dave!
|
|
|
|
|
I want to draw a graph in VB.NET.
I use visual studio 2005.
My problem is that I want to draw graph dynamically for every second
For Example: There is a person on bicycle who is going at different speeds at different times. And that data is simulated in VB
Now I want to draw a graph of speed vs time something like for fisrt second what is the speed (to be plotted on the graph) and for next second what is it and so on.
Could anyone please help me on this front.
Thank You
Edit/Delete Message
|
|
|
|
|
Google for "ZedGraph". The rest is easy, merely setting up the graph to look the way you want, then passing in the data every second. The graph draws itself.
|
|
|
|
|
Hi,
i want help in writing a savefunction in vb.net.
requirement is:
An array of hat objects is passed into the function. The hat in each object is then saved to the database table.The following properties are set in each hat object :objectID,date,quantity.
Table used is hat1
Parameter passed into the function is arrayhat which is an array of hat objects.
using .net2.0/vb.net/oracle.
Thanks
|
|
|
|
|