|
No worries - glad to help. That's exactly what I thought your code must look like, and exactly what I was suggesting as a fix.
ShowDialog returns an enum called 'DialogResult', that's what you'd use if you wanted to do something based on what button a user clicked to close a child dialog, for example, you'd check if it was DialogResult.OK before doing any processing, the other option being that they pressed cancel and you wanted to do nothing.
It's not usual for a form to hide itself while a child form is visible - do you have a good reason to do this, in this case ? It's just not what the average user would expect, based on the behaviour of other applications.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Small problem here. When using .ShowDialog() , it's a good idea to dispose the form when your done with it. The form holds open unmanaged resources that should be released when your done with them and not rely on the GC to do it for you whenever it gets around to it.
Private Sub btnDataEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataEntry.Click
Dim frmDataEntry As New DataEntry
Me.Hide()
frmDataEntry.ShowDialog()
frmDataEntry.Dispose()
Me.Show()
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I would put a property in form2 such as
<br />
public property CalledFrom(frm as Form)<br />
Get<br />
return m_Frm1 <br />
End Get<br />
<br />
Set(value as Form)<br />
m_Frm1 = value<br />
<br />
End Set<br />
Then in form1 do something such as:
dim f as New Form2<br />
f.CalledFrom = me<br />
f.Show
Then in form2 call the form from the variable.
m_frm.show 'or m_frm.Visible = True may work<br />
me.dispose
|
|
|
|
|
The main reason that this is a bad idea, is that Form2 should not be responsible for if Form1 is visible or not. It's bad OO.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hmm, well, I am not trying to make Form2 reponsible for anything. All I wanted to do is just hide Form1 for a while while I am working on form2 and when I am done with form2 and closes it, form1 will just pop back out..
|
|
|
|
|
But have to agree with Christian though, it does seem rather abnormal that someone would try to do something weird like that. And BTW, Lespaul, thanz for that little bit of code u suggested but sadly, I dun dig it at all... Like I mentioned, I am a new born baby VB.net programmer... Still sucking on milk, so to speak... hehehe
|
|
|
|
|
What you've done above is good. What this other guy suggested is bad, he wants Form2 to contain the code to show Form1.
But like I said above, I don't think it's a good idea to hide Form1 necessarily, as I don't know of any other apps that do this. When you call ShowDialog, Form1 will stay visible if you let it, but it won't respond to input.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
ohh.. i see... no point in saying what he did is good or not though, since I dun see how his code runs..
BTW, you guys have any idea how to implement crystal reports..?
|
|
|
|
|
I have no idea, and he won't have got an email notification. Your best bet is to google first, then if you need more info, ask a new question so people who know Crystal Reports see it and can answer it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
I have had a few times when it was necessary to hide form1 and then make it visible again when form2 closed. I found that it didn't always become visible again. Probably a focus issue and I have not had to deal with that very much in vb.net.
While I agree that it is a dirty way of doing it, it worked.
|
|
|
|
|
I want to change the back color of a column in a listview control. I thought I was on the right track by capturing the backgrounderase message and then using this routine
Try<br />
If Not Me.mcolSelectedCol.Equals(Nothing) And Not e.Header.Equals(Nothing) And Me.View = View.Details Then<br />
If Me.clv1.HeaderHandle.ToInt32 <> 0 Then<br />
'Dim int As Integer = SendMessage(Me.clv1.HeaderHandle, Win32.WindowsMessages.HDM_GETITEMCOUNT, 0, 0)<br />
Dim rec As Win32.RECT = Me.arrRects(mintCurColumn)<br />
Dim sz As New Size(rec.right - rec.left, rec.bottom - rec.top)<br />
Dim g As Graphics = Graphics.FromHdc(e.Msg.WParam)<br />
g.FillRectangle(New SolidBrush(Color.Red), rec.left, Top, rec.right - rec.left, Height)<br />
End If<br />
<br />
End If<br />
Catch ex As Exception<br />
<br />
End Try
But no luck as of yet. I have some c# code, but I can't seem to get through all the extra stuff to just pull this code. Any help would be great.
TIA
|
|
|
|
|
Found how to do it.
Friend Const LVM_SETSELECTEDCOLUMN As Integer = (LVM_FIRST + 140)
SendMessage(lstView.Handle, Win32.WindowsMessages.LVM_SETSELECTEDCOLUMN, ColumnIndex, 0)
lstview.invalidate()
|
|
|
|
|
how to search for a specific record in a database using a Button on vb.net?
|
|
|
|
|
The button does nothing for the database, it raises an event. Your code which catches the event is free to do whatever it likes, including connecting to the database, runing some SQL ( which may well return a search result ), and then doing what ever it likes with the result ( which could include displaying it to the user )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Hi.
I want to change a file name:
filename.jpg.lnk
to read:
filename_t.jpg
I know that I can shave off the .lnk with:
file.Name.Replace(".lnk", "")
But how can I also add the "_t" to the final file name?
Thanks
Brad
|
|
|
|
|
You could split the filename up into substrings using the .Split() method. Then just modify the individual substring however you want, then paste them back together again:
Dim myFile As New FileInfo("filename.jpg.lnk")
Dim filenameParts As String() = myFile.Name.Split(".")
Dim newFilename As String = filenameParts(0) & "_t." & filenameParts(1)
It's up to you to add an error checking code you want and conditional statements to make sure that it is, indeed, OK to modify the supplied filename the way you want.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
How can I display the the line I have just highlighted in a datagrid.
e.g.
ID Surname Forename Department
1 Smith Alan Sales
2 Brown Liz Accounts
3 Green Peter Sales
These are the values I have on my datagrid. If I highlight ID 2, how can I display the values. These values I am going to use on another form so to modify certain values.
Does this make sense?
|
|
|
|
|
i'm not sure i understand your sentence how can I display the values ?
what do you call "display" here ? i think it is already displayed 'cause you already see it on the screen...
anyway, you can use DataGrid.CurrentRowIndex() and DataGrid.CurrentCell() to recover the cells of the selected row on the DataGrid...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
hi, all
i am going to implement a WinForm Control which contain a picturebox control , i want to draw lines on the picturebox , when i drags the mouse(left button) , a straight line will be drawn, and whenever i right clicked on one of the lines , it will disappear, how to implement this by GDI+ , can anybody post some sample code here or some URL may helpful.
any suggestion would be appreciated! thanks a lot
best regards,
nick kong
debug.writeline("am i sexy")
|
|
|
|
|
the only way I know of to get rid on lines is to refresh the control. This will get rid of all the lines though. I would use an array to either save the line draw info.
|
|
|
|
|
thank you, Mr.anonymous,
you mentioned use array to save line draw info, can you show me some sample code ? i made some pseudo code like this
i define a structure to store information of the line cooridanites , like this :
structure LineInfo
strartPoint as point
endPoint as point
myColor as color
paintORnot as boolean
end structure
but i think it's useless, base on these infomation , i can not find the line i want to erase, and when i drew thourands of lines, the search procedure would cost huge system resource, i think , right?
what u think of this ?
thanks ,
nick
debug.Writeline("am i sexy")
|
|
|
|
|
GDI+ is responsible for drawing lines. I'd ditch the picturebox and just draw your image on screen. I can't imagine it will add anything and could be a pain.
Undo works one of two ways.
1. Keep copies of all your bitmaps every time a drawing event occurs, so you can go back through them
2. Keep all your actions in a list, so you can remove one, and apply the rest to the original image, resulting in an undo
1. is easier to write, 2. is more memory friendly and flexible.
Christian Graus - Microsoft MVP - C++
|
|
|
|