|
Hi,
two comments:
1.
a PictureBox is not the right Control for this; its purpose is to show an existing Image,
no more, no less. Yours is not an Image, it is a painting that keeps evolving. So
I would suggest you take a simple Panel.
2.
The normal draw approach is to:
- have some data structures that represent the entire content of your drawing/painting;
- use keyboard/mouse events to modify these data structures;
- have the Paint handler "execute" the data structures, i.e. do the actual Graphics
operations.
As a result, you have:
- data structures ready for saving/restoring your structured document to /from file
- a visible result that gets redrawn automatically whenever it needs to (e.g. because
you resize the Form, uncover it, etc).
- the possibility to resize your drawing/painting based on its high-level representation
(such as font size), rather than pixel-based.
Now for real painting, the above may be rather difficult; if so, you could use a Bitmap,
create a Graphics for it once (with Graphics.FromImage; keep it in a class member),
and paint into that Graphics from your keyboard/mouse event handlers, then Invalidate()
your Panel. In the Panel's Paint handler simply DrawImage() the Bitmap.
But don't first paint on the screen, then try to capture the screen. That is inefficient
at best.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi
Luc Pattyn
thanks for the info...
I will like to let my problem in more detail...
I have to use a tablet attached to the PC which acts as a input device for user
Was successfully able to do all what i told in my question in Vb6
Now when i migrated the code to Vb 2005 I was Not able to do it properly...
Issue is, the tablet sends packets as the user user writes on it... The tablet is of A4 size and the user can write on whole page
If i Use a data structure to store all points and then draw lines between them then one thing the data structure becomes too big and in low config system there is a threat of crashing or system becomes slow
other aspect is that a user will like to see what he writes in a similar size as what e is writing inso i need to make the picture box big which scrolls on the window...
As you suggested, if I use a panel then can i do all the above??
|
|
|
|
|
Hi,
1.
yes I would use a Panel for this.
2.
I would also try and avoid scrolling.
What is the resolution of the tablet (how many points can it discern horizontally and
vertically) ? if that is less than there are pixels on the screen, I would do a one-on-one;
if the tablet resolution is quite different, I would use some scaling so it still fits
the (height of the) screen.
3.
Assuming a lot of data is coming in, I would use the bitmap approach: allocate a bitmap
of the right size, get a Graphics for it; then accept tablet input and paint into the
bitmap using that Graphics.
4.
New suggestion: don't Invalidate() everytime you modify the bitmap, just set a boolean flag.
Then install a Windows.Forms.Timer that ticks say once every 100 or 200 msec; in its
tick handler, if the flag is set, clear the flag and Invalidate the Panel.
As a result you can accept data at full speed, and your screen would be refreshed every
100 or 200 msec (rather than every time the bitmap changes).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
All of my applications have migrated to VB 2005. They all start from Sub Main in a module.
Today I decided to create a new one and set "enable application framework" to true so that I can explore its new features.
The program has been run many times as I add new components. There have been no apparent problems.
I added code that creates a delegate to display the program's name and a date/time string as Form1's text.
It is invoked once a second by a thread spauned by my "Clock" class that runs on a background thread.
I encountered this error when it ran.
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
How does one create a handle for Form1?
Why wasn't it created automatically when the application started?
Thanks
RCarey
RCarey
|
|
|
|
|
RJGCarey wrote: How does one create a handle for Form1?
You don't. It's automatically created.
The problem is caused by your code not waiting long enough for the window to be completely created. Basically, you're trying to update the window before it exists.
You can either delay starting your "Clock" class or, in the update code, check the Form's IsHandleCreated property before you try to update the Form.
|
|
|
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbgS As String
bmpMain = New Bitmap(pbMain.Width, pbMain.Height)
AddHandler pbMain.Paint, AddressOf pbMain_Paint
bmpBars = New Bitmap(pbBars.Width, pbBars.Height)
AddHandler pbBars.Paint, AddressOf pbBars_Paint
instDelFormText = New delFormText(AddressOf FormText)
Shw.SetUp()
'error handling is now available
Try
MySql.Open()
Thread.Sleep(5000)
dbgS = Me.IsHandleCreated
Clock.Start()
Catch ex As Exception
Shw.Err("Form1_Load " & ex.Message)
End Try
End Sub
Put in the sleep. It does sleep.
put in dbgS. It Shows true.
Same error.
Thanks
RCarey
RCarey
|
|
|
|
|
Hi,
putting a Sleep in the main thread won't help, it just stops the world for a while,
nothing happens any more, no handles would get created in the mean time.
Where is it failing? Look at the line numbers in the Exception, and watch the line
numbers of your source code.(See my tips!)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Here's my code.
This code is in my 15+ other applications and it works all the time.
Form1
Private Sub Form1_Load
instDelFormText = New delFormText(AddressOf FormText)
End Sub
Public instDelFormText As delFormText
Public Delegate Sub delFormText(ByVal inText As String)
Private Sub FormText(ByVal inText As String)
Try
Me.Text = inText
Catch ex As Exception
Shw.Err("frmMain.WriteFormText " & ex.Message)
End Try
End Sub
Module Clock
Private Sub DoNewSecond()
Try
Form1.Invoke(Form1.instDelFormText, CObj("BarHunter 2005" & Space (100) & Now.ToString))
Catch ex As Exception
Shw.Err("Clock.DoNewSecond " & ex.Message)
End Try
End Sub
The failure occurs on Form1.Invoke etc
Thanks
RCarey
RCarey
|
|
|
|
|
Hi,
there is less code now than there was before in Form1_Load. The Form1 constructor is missing,
the Clock stuff is not complete.
Where do you start the clock? I would do it as the last thing in Form1_Load
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
My last post was just an abstract. The post prior to that has all the code. Starting the clock is the last thing in Form_Load.
In my other applications the form is created in Sub Main.
Here is the code.
Public Sub Main()
frmMain = New Form1 'new form
frmMain.Show() 'show it
Shw = New clsShow 'new class
Shw.SetUp() 'set up the graphics
cName = SystemInformation.ComputerName() 'get computer name
handleEndWorking = Now.ToString("yyyyMMdd") 'set the handleendworking
mySql = New clsMySql 'connect to the database
hntB = New BarHunter.clsBase 'new hunting base class
hntB.setUp = New BarHunter.clsSetUp 'new set up class
hntB.setUp.DoIt() 'do the job
hntB.setUp = Nothing 'dispose
Application.Run() 'run
End Sub
Now I just discovered that when I run my Show Procedures from another thread it doesn't work. It modifies a bitmap linked to a picture box on the form and then invalidates that picturebox.
Enable application framework sure creates a different critter.
Thanks
RCarey
RCarey
|
|
|
|
|
Hi
Can anybody tell me how can I call a procidure requiring arguments with a new thread. e.g. a code snippet like this.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim trShow As New Thread(AddressOf ShowMessage) 'error
End Sub
Sub ShowMessage(ByVal message As String)
MsgBox(message)
End Sub
Thanks for replying for a hobbyist progarmmer.
reman
|
|
|
|
|
Which version of VB.NET??
|
|
|
|
|
Create a new instance of a class passing parameters.
Create a new thread pointed at the sub in that class that does the work.
Name and start the thread. If you want you can wait till the thread finishes(Join) and then dispose of the instance of the class.
Here is a code snippet.
SQL.B.setDay = New SQL.clsSetUpAnyDay(Now.Date) 'new class
thdWorker = New Thread(AddressOf SQL.B.setDay.DoIt)'new thread
thdWorker.Name = "setDay" 'name it
thdWorker.Start() 'start
thdWorker.Join 'wait till it finishes
SQL.B.setDay = Nothing 'dispose
Hope that helps.
RCarey
RCarey
|
|
|
|
|
I have a Crystal report and a CrystalReportviewer and i want to put a button to open pagesetup for this report.In the CrystalReportViewer toolbar i see only a print , zoom and some other buttons but no Pagesetup.
Any idea
Thanks.
|
|
|
|
|
hey guy
if u click on print button at cr report it will automatically display the pagesetup or print option
if u want to seprate add a button then write code
crrptview.printreport=true
hope u understand
lucky
|
|
|
|
|
Hi,
I'm trying for days now to figure out how to implement "Volume Shadow Copy Service" (VSS) under vb.net.
The goal is to get a tiny application the runs at XP, Vista and 2003 to make backups of files in use (locked).
I read almost the complete Internet and Google-Cache but didn't find any helpful startup-point. The "Volume Shadow Copy Service SDK 7.2" is C++ only, what's definitly not my language
Documentation can be found at: http://msdn2.microsoft.com/en-us/library/aa384961.aspx[]
Anybody out there that can give me a hint
Regards,
wtfia2k
|
|
|
|
|
Interesting.
Well, the documentation was written for a target audience of C++ developers, but that hardly makes the SDK "C++ only".
Though I can't find any VB.NET, or any other language, code samples, it's possible to use the VSS from VB.NET. Start by adding a COM Reference, in your VB.NET project, to the Volume Shadow Copy Service, then open the Object Browser and look through the Interop.VSS item listed in the browser.
You are venturing into uncharted waters here. You probably will not find any articles, samples, or knowledgable help on using VSS from your app.
|
|
|
|
|
Dave Kreskowiak wrote: Interesting.
glad to here
Dave Kreskowiak wrote: Though I can't find any VB.NET, or any other language, code samples, it's possible to use the VSS from VB.NET. Start by adding a COM Reference, in your VB.NET project, to the Volume Shadow Copy Service, then open the Object Browser and look through the Interop.VSS item listed in the browser.
that's exactly what I did - so far so good.
Thanks for acknowledging me.
Dave Kreskowiak wrote: You are venturing into uncharted waters here. You probably will not find any articles, samples, or knowledgable help on using VSS from your app
I feared that unfortunately in such a way.
Regards,
wtfia2k
|
|
|
|
|
Thanks again to Dave Kreskowiak who confirmed my idea to use the com-object "Volume Shadow Copy Service 1.0 Type Library".
After fooling around a bit with it I'm that far, that I really make Shadow Copies
Here is the code how I've done it (in a quick and dirty manner, of course )
Dim vshadow As New VSS.VSSCoordinator<br />
Dim snapshotSetID As System.Guid<br />
Dim _snapshotID As System.Guid<br />
<br />
vshadow.StartSnapshotSet(snapshotSetID)<br />
vshadow.AddToSnapshotSet(root, System.Guid.Empty, _snapshotID)<br />
<br />
Dim vssAsync As VSS.IVssAsync = Nothing<br />
Dim callback As Object = Nothing<br />
<br />
Debug.Write("starting shadow copy .")<br />
vshadow.DoSnapshotSet(callback, vssAsync)<br />
While True<br />
Dim hr As Long<br />
vssAsync.QueryStatus(hr, 0)<br />
Debug.Write(".")<br />
If DirectCast(hr, IVssAsyncQueryStatus) = IVssAsyncQueryStatus.VSS_S_ASYNC_FINISHED Then<br />
Exit While<br />
End If<br />
Thread.Sleep(1000)<br />
End While<br />
Debug.Write(" done!")<br />
Debug.WriteLine("")<br />
<br />
Debug.WriteLine("examine snapshot")<br />
Dim snapshotProps As VSS._VSS_SNAPSHOT_PROP = Nothing<br />
vshadow.GetSnapshotProperties(_snapshotID, snapshotProps)<br />
<br />
Dim _snapshotDeviceName As String = snapshotProps.m_pwszSnapshotDeviceObject<br />
Debug.WriteLine("Shadow copy device name: " & _snapshotDeviceName)
So far - so good! But how to access the shadow copy to extract files out of it?
Trying someting like this:
Dim ShadowedRoot As String = Nothing<br />
vshadow.ExposeSnapshot(_snapshotID, Nothing, 1048576, "C:\ShdwOfC", ShadowedRoot)<br />
'vshadow.ExposeSnapshot(_snapshotID, Nothing, _VSS_VOLUME_SNAPSHOT_ATTRIBUTES.VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY, "c:\ShdwOfC", ShadowedRoot)<br />
Debug.WriteLine("ShadowedRoot: " & ShadowedRoot)
crashes with an NotImplementedException.
What the he.. !!! Does this really mean, it's not implemented in the com yet, or am I doing something completely wrong? (a lot of wood, but now trees ...)
Regards,
wtfia2k
|
|
|
|
|
Well, either the COM interface hasn't been impemented or the parameters are wrong (which it doesn't look like they are), or certain functionality hasn't been fully implemented depending on the values of certain parameters.
I would recommend trying to expose the snapshot as a share on the server to see if that works. If it also fails, then I would have to believe that ExposeSnapshot hasn't been implemented through COM yet.
|
|
|
|
|
I have some DataGridViewComboBoxColumn s in my datagridview. I have all of the code working correctly but I would like to find a way to have the CellValueChanged event fire when the new value is selected in the comboboxcolumn and not after a value is selected AND I click outside of that cell to commit it.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
The Cell value won't change until the cell loses focus. Until then, you're still editing it.
The Cell's value doesn't pickup the value of the ComboBox until focus is lost. This is when the SetValue method of the DataGridViewComboBoxCell is finally called, which sets the value of the DataGridViewCell, which fires the CellValueChanged event. The DataGridViewCombBoxCell doesn't expose any events itself, so I don't know how you're going to know when the ComboBox value changes.
|
|
|
|
|
Hi ol
My name is yasin
i am currently developing an application in vbnet 2003
the requirements are as follows:
On the form will be located a number of points (no more than 4) through a light ray must pass. The light ray emerges in a specific direction from a fixed point.
Pls note the light ray is to be represented by a line
The light is deflected by reflection using a suitable number of plane mirrors.
Note that for a plane mirror the angle of reflection and the angle of incidence are equal.
The simulated system must allow the user to place simulated mirrors in the enclosed area to reflect the light ray to follow a path that will make the light ray illuminate all the designated fixed points.
this means dynamically placing lines (simulated mirrors) with mouse operations in the path of the simulated light beam; another line.
As soon as a mirror is placed then the light beam will be reflected and thus change course. Clearly the first attempt of placing the mirror is unlikely to direct the beam exactly as required so is essential that the mirror can be rotated about the point where the beam hits until the desired effect is achieved.
Once the simulation is showing the light beam passing through all the designated points then the system will report on the exact location and orientation of the mirrors.
At the moment i have managed through some research to create a label which can be moved around the form at runtime. the label will repersent the mirror. I even have the four fixed points and the source of the light ray on the form. By instantiating a class called clsBeam i can even draw the lines which will represent the the beam
Any ideas or even code on how to deflect the line (light ray) and how to rotate the label about the middle point will be highly appreciated.
Thanking you in advance.
Regards
|
|
|
|
|
Sounds like an interesting piece of homework. The deflection of the light, to do it correctly, would involve reading up on some physics. As for the rest, you should ask specific questions as you get stuck, rather than ask us to provide code for you.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
Yasin786 wrote: Any ideas or even code on how to deflect the line (light ray)
This is simple Trigonometry, vector math. Open your math book from school.
Yasin786 wrote: how to rotate the label about the middle point will be highly appreciated
A don't think a label control is a good starting point for this control. You're going to need to move as well as rotate to any angle, so you're going to have to come up with a custom control for this.
You start by reading up on creating selectable and moveable graphics images here[^].
Or, if that's too much to go through, you can search for a graphics library that gives you this ability.
|
|
|
|
|