|
I'm writing a class project in visual studio 2003.
Part of the data used by the classes is stored in xml files that the user will be able to edit.
The classes are used by other applications and an end user could have more than one of these applications on their machine.
How do I distribute the classes so that they know where to find the xml data files every time and they are only saved once.
I had originally used the Application.StartupPath to find the folder where the class dll file is stored but, when I create another application the value returned by Application.StartupPath doesn't return the folder where the xml data files are stored it returns (quite rightly) the folder of the original application.
Any idea on how I go about distributing and accessing these xml files?
Any help would be gratefully received as this is a project I intend to open up on a 'do-what-you-want' licence without copyright and for all to use.
Thanks in advance
An optimist's glass is half full.
A pesimist's glass is half empty.
An engineer goes and gets the right size glass.
|
|
|
|
|
Hi All
Its a very simple code.
Project has 3 forms. On load of the first form say Form1 I am creating a new thread. Under this thread I am intitializing the timers of Form2. And then show a different form say Form3 using showdialog
but I am not able to understand why doent the timer event of the timers present on Form2 gets called inspite of being intialized under the start of the thread.
Please help me to find the reason why doesnt this code work
See the code below
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public NewThread As System.Threading.Thread<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
NewThread = New Threading.Thread(AddressOf StartNewThread)<br />
NewThread.Start()<br />
<br />
Dim objFrm As New Form3<br />
objFrm.ShowDialog()<br />
End Sub<br />
Private Sub StartNewThread()<br />
Dim obj As New Form2<br />
While True<br />
If (obj.Timer1.Enabled = False) Then<br />
obj.Timer1.Start()<br />
End If<br />
If (obj.Timer2.Enabled = False) Then<br />
obj.Timer2.Start()<br />
End If<br />
End While<br />
End Sub<br />
End Class<br />
<br />
<br />
Public Class Form2<br />
Inherits System.Windows.Forms.Form<br />
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick<br />
MsgBox("Inside timer event of timer1")<br />
End Sub<br />
<br />
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick<br />
MsgBox("inside timer event of TIMER2")<br />
End Sub<br />
End Class<br />
<br />
<br />
Public Class Form3<br />
Inherits System.Windows.Forms.Form<br />
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Application.DoEvents()<br />
End Sub<br />
End Class
Thanks,
~VanitaJ
|
|
|
|
|
Well, I've never put Form's-based Timers in other threads. In theory, though, they're not working because the Timer Tick events are not getting to the forms because those forms are on seperate threads from the main UI thread of your application.
In the example code you've posted, there is no need for seperate threads at all. You shouldn't be putting different forms on seperate threads. All your forms go on the UI thread, while background work goes into seperate threads and uses Invoke method calls back to their parent forms to have the forms update themselves with new data.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave.
I have to achieve something similar. Hence trying out a small example with 3 forms.
~VanitaJ
|
|
|
|
|
How can I set focus on a TextBox in a given row in a DataGrid?
Thanks
-- modified at 8:51 Monday 5th December, 2005
Or How can I change the Tabstop propery to false on certain column in a Datagrid?
I've tried this but it does not work.
grdColumnStyle2.TextBox.TabStop = False
|
|
|
|
|
I want to use the serial port to flash a led. Is there a simple way to acces the serial port.
Al I want is a snippet that can put a signal on the serial port where the led is connected
|
|
|
|
|
The serial port is a poor choice to do this because you would have to constantly raise a signal to keep the LED lite. The parallel port is a much better choice and there are plenty of examples on how to do it.
Also, there is no "easy" way to do this. Low-level hardware control is beyond the ability of VB.NET or C# code alone. You need a .DLL that runs inside Ring 0 (device drivers) to handle the hardware for you.
You can find a pretty good example of parallel port control at http://www.logix4u.net. For more than that, just Google for "VB parallel LED".
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks, but ...
The parallel port is already in use.
The only thing i have to do is after pressing a button on the screen send a single pulse to the serial port for opening a lock. I have a opto coupler for saftey, so a single flash from the led is all it takes.
|
|
|
|
|
The problem with that is the pulse comming from the serial port usually isn't long enough to allow an LED to completely illuminate.
You can TRY this (lifted from Experts Exchange):
MSComm1.CommPort = 1 'select your com port either 1 or 2 or 3 if you have it
MSComm1.Settings = "9600,n,8,1" 'this must be configured to your specifications
'9600 is the baud rate, n is no parity bits, 8 data bits and 1 stop bit
MSComm1.PortOpen = True 'opens the port
End Sub
'To send data from the com port
Private Sub cmdSend_Click()
MSComm1.Output = "111111111111111"
End Sub
It uses the old MSCOMM control from the VB6 days. There's virtually no examples of doing this, because of the problems with using the serial port to do anything useful with an LED.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
You could use a microcontroller and send data via the rs232 port!
I don’t know your electronics abilities, but a simple PIC16F84 or PIC16F628 would be suitable, you can even use BASIC to program the PIC. Just create a basic selection program and control it via VB.NET.
Trust me there are thousands of examples on the net!
|
|
|
|
|
Hello,
I am coding a text editor program. I creat my main form with a menu. While the user hit a menu item, a different form would come out and ask for input. After that, I would like the change reflected in the main form, say, TextBox1 in the main form.
Can somebody give suggestions?
Best,
Hui
|
|
|
|
|
Different way of accomplishing it.
Common one, and easiest, is:
sub form1clickwhattever....
form2.show
me.textbox1.text = form2.controlwithdata.text
end sub
|
|
|
|
|
Thanks for the reply. I tried to use the code in my program. However, it does not work. I would like the me.textbox1.text get changed after the user click on an OK button in the 2nd form. The code above replaces the textbox1.text with a blank string, since the user has not filled out the info yet. I guess that I need to refer to the caller (main form) in the called form (child form), but I don't know how to refer to the main form in the child form. In Visual Basic 6, I think I can just call its name but not in Visual Basic .Net. Any suggestions?
|
|
|
|
|
Well my code has an error or better it was missing the form2.showdialog (so that the next line is executed only after the form2 has been hidden/closed with the button).
So if you replace .show with .showdialog then it works.
Anyway if you want a more precise answer you should provide more precise informations. Which versione of FW are you using 1.x or 2? VS2003 or VS2005.
In VS2003 you can refer to the calling form only if it's public declared.
Module x
public fmain as new frmMain
end module
then in the form2 button click event handler:
fmain.textbox1.text = ....
In VS2005 in most cases you can state immediatly the form without instancing it. This means you can have a direct access to frmMain (considering the previous example) unless you're running an instance created by you (than you fallback in the former case).
Another way of doing it is by raising an event.
In form2 you'll have:
...
raisevevent OKClicked()
and in form1
private sub ClickOnForm2() handles frm2.OKClicked
me.textbox1.text = frm2.textbox1.text
end sub
or using parameters ...
public class frm2eventargs
inherits eventargs
public t as string
end class
on form2 before you raise the event...
dim e as new frm2eventargs
e.t = (text to pass)
raiseevent OKClicked(me,e)
and then on the mainform
private sub frm2OKClick(sender as object,e as frm2eventargs) handles frm2.OKClicked
me.textbox1.text = t
end sub
So as you can see lot of options depending on the approach you want and what you're using.
|
|
|
|
|
At a other site on the web (http://www.codeguru.com/columns/VB/article.php/c6529[^]) I found a sample for TypeConverters. I played a little with this sample: I added a new class 'TestControl' (Inherited from UserControl) with one userdefinded-Property 'TestProperty As Circle'. If I add my TestControl to a Form, the IDE generates the following Code:
Me.TestControl1.TestProperty = CType(resources.GetObject("TestControl1.TestProperty"), tester.Circle)
And now there comes my problem: I want that the TestProperty becomes a ReadOnly-Property and die generated Code has to look like this:
Me.TestControl1.TestProperty.X = 4<br />
Me.TestControl1.TestProperty.Y = 5<br />
Me.TestControl1.TestProperty.Radius = 3
Is this posible or want I too much?
|
|
|
|
|
|
The second time you helped me much. Thanks
|
|
|
|
|
Your welcome (for both times of course )!
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
Is there simple way to find out how many records there are in a database table? Access database table that is.
|
|
|
|
|
The only way with Access I knowing is the following SQL-Statement:
SELECT COUNT(*) AS TableCount FROM [Table]
|
|
|
|
|
Hi
I am trying to draw a rectangle over an existing image by using the following code (pb is the PictureBox and has an image)
<br />
Dim oGraphics As Graphics = Graphics.FromImage(pb.Image)<br />
With oGraphics<br />
.DrawRectangle(New Pen(Color.Red, 2), New Rectangle(5, 5, 300, 300))<br />
End With<br />
pb.Refresh()<br />
The problem comes when I want to draw another rectangle (at a different location) and I can't remove/clear the existing rectangle before drawing the new one.
Is there any way I can remove the existing drawn rectangle?
I don't want to use the pb.CreateGraphics() b/c the drawing is not consistent when this method is used.
I am using the FromImage() method b/c later I want to resize (zoom) or rotate the image with drawn rectangle and It won't require any further coding for rotating and resizing the rectangle.
I tried reload the Image again, but large images take to much time to load, so I want to avoid the Image reloading.
Please help!
|
|
|
|
|
Maybe you can load the image, and the clone it, and the put the clone in the pb? That way, when you want to remove the stuff you were drawing on the image of the pb, you can dispose that image and put a new clone of the original in the pb. I think on large images cloning takes much time too, but less that reloading it.
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
I haven't worked with graphics for a while, so I don't know how hard this would be, but could you lay down the image first, and then overlay a transparent picturebox on the first image? Then, instead of drawing the rectange directly on the image, you can draw it over the image, on the second picturebox.
Roy.
|
|
|
|
|
Thank You Roy,
I am not sure and don't remember it correctly (I read it somewhere) that there is something like a Xor Pen.
Is there anything like this that can help me?
Another CP user in the C# forum suggested me that I should remember the Pixel values of the image (for rectangular area) before drawing the rectangle. How do I remember those values and how to reload those values?
|
|
|
|