Program fine tuning: Skinning & Startup a windows forms app with only one instance like medi
I have several programs that are done in VB.NET. i want to fine tune in the following ways, i don't know how it's done. I want to be the only allowed instance of the proccess running. (ini file that just says it's running?) and exits, or is there a parameter for this? is it in the registry? That would contradict the following thing i want to add. How do you have your program open like when media player is open, and you double click a file it doesn't open a new instance it opens it in meida player. And i want to add a link to the quicklaunch, how do you do this, it's not hidden in the my namespace is it?
1. open a file in an instance already running by double clicking the file like media player does with mp3's instead of opening another instance of media player when you double click a song.
2. only one instance allowed to be running. (can't do this with an ini file because i you would have to put a line inpublic shared mainto check the registry and then exit, the file needs to open in the instnace that's already open) and an ini file or registry hack would make that bypass to a new instance of a program.
3. add a link to the shortcut quicklaunch menu. i found this article that doesn't cover it, but close.http://support.microsoft.com/?kbid=155303
4. does anyone know how to skin a window form? like make the bg a picture?
--Jay
[1509 byte] By [
JohnX.C.] at [2007-12-22]
2. You can check the running processes....
Dim
proclist() As Process = Process.GetProcessesByName(processName)For Each p As Process In proclistIf p.Id <> Process.GetCurrentProcess().Id Then' process is already running, so tell the new copy to exitEnd IfNext
where procesName is the name of your app.
1. Then in your sub main or startup project, if you're already running then you know you won't start a new copy, so then you can simply deal with the file they tried to open
3. Quick Launch links are usually stored in C:\Documents and Settings\<USER>\Application Data\Microsoft\Internet Explorer\Quick Launch so I guess you could write a .lnk file there fairly easily using a shell script like CreateShellLink
4. http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1699&lngWId=10 might help
4. Just set the form property BorderStyle to 'None' and set TransparencyKey to the color 'Control'. To make a picture in the bg obviously add a picturebox on the form with a gif.
Now doess anyone know how the startDrag and stopDrag the form, I searched objectbrower but only found BeginDrag and EndDrag.. but this method does not work. I saw this in an article referencing media player once.
Thank you
This is the code i'm using.
I searched the fourms for TransparencyKey, it's gotta be the only use for it! Then i found this post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=452707&SiteID=1 that point to this article:
http://www.thecodeproject.com/csharp/CustomForms.asp
And that's where i found the code to get the mouselocation from the control class and then offset the position to move the form
here's my code:
Public
Class Form1 Dim mousedownvar As Boolean = False Dim mouseoffset As New System.Drawing.Point(0, 0) Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown mousedownvar =
True mouseoffset =
New System.Drawing.Point(-e.X, -e.Y) Dim control As Control = sender'TextBox2.Text = control.MousePosition.X'TextBox3.Text = control.MousePosition.Y'TextBox4.Text = Me.Location.X'TextBox5.Text = Me.Location.Y End Sub Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp mousedownvar =
False End Sub Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove Dim control As Control = sender'Dim xoffset = mouseoffset.X'Dim yoffset = mouseoffset.Y'TextBox2.Text = control.MousePosition.X'TextBox3.Text = control.MousePosition.Y'TextBox4.Text = Me.Location.X'TextBox5.Text = Me.Location.Y'TextBox6.Text = xoffset'TextBox7.Text = yoffset Dim mousepos As System.Drawing.Point = control.MousePosition mousepos.Offset(mouseoffset.X, mouseoffset.Y)
If mousedownvar = True Then If e.Button = Windows.Forms.MouseButtons.Left Then Me.Location = mousepos End If End If End SubEnd
Class
ok that's it, it's working for me.
--Jay
i forgot to make it resize, just add a label id label1 and copy and paste these events.
Private Sub Label1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown mousedownvar =
True mouseoffset =
New System.Drawing.Point(e.X, e.Y)End SubPrivate Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp mousedownvar =
FalseEnd SubPrivate Sub Label1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove If mousedownvar = True Then Dim offsetx As Integer = e.X - mouseoffset.X Dim offsety As Integer = e.Y - mouseoffset.Y Me.Size = New System.Drawing.Size(892, Me.Size.Height + offsety) End IfEnd Sub
This sample uses code from a previous post so you must use both examples for it to work.