|
Hi,
I think this code will fullfill your need.
'--- BEGIN
Private Btn As Button
Private y As Integer = 10, ID As Integer = 1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Btn = New Button()
Btn.Location = New Point(10, y)
Btn.Text = "Button" & ID.ToString
AddHandler Btn.Click, AddressOf Hai_Click
Me.ParentForm.Controls.Add(Btn)
y += Btn.Height
ID += 1
End Sub
Private Sub Hai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim C As Control = sender
MsgBox("Hello Friend....! U Have Selected " & C.Text, MsgBoxStyle.Information, "")
End Sub
'--- END
|
|
|
|
|
Hello,
I am writing a UserControl in VB.NET. The UserControl has a class called NotifyClass. I have one USB device and when this device is connected to PC, I am taking this event to call the NotifyClass. On the other side, I have application in VB.NET which also calls a method a function in UserControl to pass some input parameters and get the result back. In short I have two instances one which calls my OCX notifyClass and one which calls OCX to get results. But these two events takes place at different times and there is no communication between them. Can anyone explain me how to implement communication between these remote objects?
I look forward to your reply.
thanks/regards,
Atul
|
|
|
|
|
Hi All,
I want to convert IntPrt back to its original Object in VB.NET.
Is it possible ? I am a newbee and I need help on this from u.
Thank you.
|
|
|
|
|
Not quite sure I get what you're asking. Could you post a code snippet/sample?
|
|
|
|
|
I am trying to figure out if VB.NET (or even VB6) is the best way to test for an existing instance of an application. Basically, I want the code to test (I assume in Processes) whether the application is already active, and if it is, not open a second instance. (Of course, if it is not already running, then the application should open). Can anyone steer me in the right direction?
|
|
|
|
|
Your application should do this, not some external application. The way you've worded this suggests that you think otherwise.
No, C++ is the best language to do this in, but if you're stuck with VB.NET, then there's no reason why VB.NET can't do it. There are tons of examples on the web, and probably even on CP. You're more likely to find them in C#, I'd have thought, but they should be easy to convert.
I have no doubt that this is beyond VB6's meagre abilities.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Yes, the base application should do this...long story as to why it doesn't.
Anyway, VB.NET is what I'm "stuck with" to achieve this objective. Can you point me to some examples "on the web" and/or CodeProject?
Thanks!
|
|
|
|
|
You can do this with API calls, which are even within the grasp of VB6 "meager" abilities. LOL.
EnumProcesses is one way but it can be cumbersome to work with.
If the application creates a main window that has a reasonably unique caption that does not change (in other words, this would never work with a web browser, but is feasible for most regular compiled apps) you can use the FindWindowEx API.
If you search for the app caption and window class, and the handle returns as zero, the app is (probably) not running.
Use Spy to help you determine the caption and window class name to search for.
Robert
|
|
|
|
|
Robert,
Thank you for the information. I am not familiar with the type of calls you are referring to. Could you provide a code example to accomplish what you are describing? Thanks!
|
|
|
|
|
Here is a quick and dirty way of checking for a process.
First you need a reference to the SystemDiagnostics.
Imports System.Diagnostics
Then
Dim myProcess As Process() = Process.GetProcessesByName("ProcessName")<br />
If myProcess.Length > 1 Then<br />
MsgBox("You can only have one instance of this application running.")<br />
End If
Hope this helps
|
|
|
|
|
Hi,
My MainForm is set as a MDI Parent and I have a number of MDI Child Forms. However, I have a problem with one of the MDI Child forms containing a PictureBox.
I am drawing my graphics offscreen (a large background jpg image onto which I draw some additional items, using GDI+), I then using BitBlt to Paint a portion of this image inside the PictureBox. (The mouse is then used to scroll the image).
If I dont have this form set as a MDI Child all works beautifully. However, when set as a MDI Child, problems arise. The image is not drawn on load and only appears when I move the mouse inside the PictureBox (as if to scroll). If I minimise the form and then maximise it - again no image appears until I move the mouse again.
My guess is that it has something to do with the Paint Event - I did read on MSDN that there is a problem with the Paint Event on MDI Children if the Opacity Property is used on the Child Form. I have left this at the default value of 100%.
Any help or suggestions would be most welcome.
Thanks,
NagaJim
|
|
|
|
|
Hi,
I need to create a crystal report in vb.net. Some fields can be pulled from database and some needs to be entered by the user. So i need to put editable text boxes in the report.
Can this be done?
|
|
|
|
|
is this anything you'd be able to handle with input parameters?
-jim
|
|
|
|
|
How do you get the correct location of the control? if it is inside a FORM within a PANEL within a GROUPBOX ?
Is it POSSIBLE to get the absolute location of the control (no matter inside of where it is?).
I want to overwrite the control with a new control.
Thanks
|
|
|
|
|
You can use left and top properties, from the microsoft reference:
Control.Left Property [Visual Basic]
Gets or sets the x-coordinate of a control's left edge in pixels.
[Visual Basic]
Public Property Left As Integer
[C#]
public int Left {get; set;}
[C++]
public: __property int get_Left();
public: __property void set_Left(int);
[JScript]
public function get Left() : int;
public function set Left(int);
Property Value
The x-coordinate of a control's left edge in pixels.
Remarks
The Left property value is equivalent to the Point.X property of the Location property value of the control.
Changes made to the Width and Left property values cause the Right property value of the control to change.
|
|
|
|
|
Yeap...Itried it it does not work.
I want the absolute position of the control.
(I want to overwrite the control)
when I try to overwrite the control using control.left or control.top and the control is within a panel it does not locate it correctly.
here is some of my code
newcontrol.left = oldcontrol.left
newcontrol.top = oldcontrol.top
oldcontrol.sendtoback
newcontrol.bringtofront
my newcontrol is set relative to the form1 not relative to my panel1 .
|
|
|
|
|
I know that...thanks
but, the point is:
I would like to get (there must be a way) the absolute positioning of the control.
|
|
|
|
|
i would say after reading your thread that the most likely problem is that you're not adding the newcontrol to the groupboxes controls collection.
a control's position property is always relative to it's immediate parent. so if you have oldControl on a panel and assign it's left property a value of 5, it will be 5 pixels (twips) off of the panel's left edge. if you have newControl directly on the form and assign it's left property a value of 5 it will appear 5 pixels off the forms left edge.
give this a try...
dim newControl as new textbox
myGroupBox.Controls.Add(newControl)
newControl.Top = oldControl.Top
newControl.Left = oldControl.Left
another way to do this would be to just create both controls at design time and position them as you wish. then at run-time all you have to do is add the code to handle hiding/showing them appropriately.
hope this helps,
-jim
|
|
|
|
|
thanks, I got some light now.
I beleive I AM adding newcontrol to the FORM1; I should added to the Panel1 inside FORM1. how do I add newcontrol into FORM1.PANEL1 form FORM2.
|
|
|
|
|
Seems we finally understood:
Dim TextBox1 As TextBox = New TextBox()
Dim ctr As New Control
for each ctr in me.parentform.controls
if ctr.name="Panel1" then
'instructions
ctr.add(TextBox1)
end if
next
|
|
|
|
|
well, the best way to do it depends on exactly what the relationship between these two forms is.
if form1 is the mdi parent of form2...
'in formTwo...
dim formOne as form1 = me.MdiParent
if form1 is set as the parent control of form2 through the .Show() procedure...
'in formTwo...
dim formOne as form1 = me.Parent
the above code will give you an instance of form1, which you'll then need to utilize to add your control.
my recommendation for doing this would be having a friend Sub to grant access for you to the controls property of the panel.
public class form1
inherits system.windows.forms.form
'--- windows generated code ---'
Friend Sub AddPanelControl(byval controlToAdd as Control, byval location as System.Drawing.Point)
me.panel1.controls.add(controlToAdd)
controlToAdd.Location = location
End Sub
End Class
public class form2
inherits System.Windows.Forms.Form
Private Sub button1_click(byval sender as object, byval e as buttonclickeventargs) handles button1.click
dim formOne as form1 = me.mdiparent 'you may need to cast this return value using ctype depending on whether or not you're using option strict on...
dim newControl as New TextBox
With newControl
.Name = "myTextBox"
.Text = ""
'etc.
End With
formOne.AddPanelControl(newControl, new System.Drawing.Point(10, 10))
End Sub
End Class
This should work out for you. I haven't tested it out or anything, but let me know if there are problems.
I would still recommend setting your controls at design time and just worrying about managing their visibility, but if you can't then this would be another way...
-jim
|
|
|
|
|
JIM:
Thanks, very close.
this is what I have.
FORM1 has the array of controls (all textbox inside a PANEL1)
lets say:
textbox1
textbox2
textbox3
when we click a control let's say textbox2:
Form2 will overwrite the control textbox2(hide The control from FORM1) and
creating the new Textbox2 (could be any type of cotrol: a textbox or Calendar or whatever) in the location where textbox2 was.
now, FORM2 has to create the control reading from a DB at run time and overwrite the one form FORM1.
If you can give one more tip...THE CREATE STATEMENT
I need to say FORM1.PANE1.CONTROLS.ADD(newcontrol) from FORM2
i DONT KNOW HOW ?
I appreciate your help.
Thanks
|
|
|
|
|
forgot!
FORM1(Is not mdiparent) does the call only by:
dim f2 as new form2
f2.loadFld(me,textbox2)
and
FORM2 has:
Public Sub Form_Load(ByVal pf2 As Form, ByVal t1 As TextBox)
|
|
|
|
|
that is what the freind sub AddPanelControl is for. in general it's nota good idea to expose properties of child controls to external resources. therefore a buffer that can control access to an exposed field can limit who, or what can access the exposed field. for instance, since the sub AddPanelControl is declared as Friend, it restricts access to only objects declared in the same project as the procedure.
so from form2 you can AddPanelControl and pass in the newcontrol you want added to the panel. the problem you're going to run into with this architecture is that you're not going to be able to destroy the initial control; or textbox1.
this is why i recommended going with a solution whereby you set everything at designtime and just check a variable state to determine the visibility of certain controls.
honestly, from your description i still don't understand exactly what you want to do.
you have a form 'form1' with a panel and for example several textboxes. when you click on textbox1 on form one you want to have form2 replace textbox1 on form1 with another control? i don't understand how this is going to work...
am i misunderstanding you?
maybe if you post the relevant code that you have from form1 and form2 i can try to figure something out.
-jim
|
|
|
|
|
FORM2 (which will be a new project) will handle all the routines for to the new textbox2 (checking and validating).
This is what I need/want to do:
We have 202 forms with diff entry fields for ea reports (CR v10).
These entry fields can be chkbox, list ,combos, and so on.
ea form could have a mix of fields as datefrom,dateto,idfrom,numfrom,numto and many more fields.
Forms can have any of these fields and ea field will have to be validated.
in a case of a IdFrom will have to have a list for the user to select from. I think I can avoid doing 202 forms if...
If I create a general FORM1 with text boxes representing ea field entry, then, when the user clicks on one of the textbox I will know what form to call and handle all the related to such field and validate such field.
So, ea field will have a Procedure to handle all related to the field (err msg,edits,checking range values or any other need).
if we have one form for ea report we have to repeat too much code.
neither, I cannot have all these code in a single form, it will be too much debugging.
|
|
|
|