Click here to Skip to main content
15,885,877 members
Home / Discussions / Windows Forms
   

Windows Forms

 
PinnedForum Guidelines - PLEASE READ PinPopular
Chris Maunder28-Jul-09 2:38
cofounderChris Maunder28-Jul-09 2:38 
QuestionCode-Behind in Designer.cs File [SOLVED] Pin
Richard Andrew x648-Jul-23 6:30
professionalRichard Andrew x648-Jul-23 6:30 
AnswerRe: Code-Behind in Designer.cs File [SOLVED] Pin
Andre Oosthuizen9-Jul-23 3:50
mveAndre Oosthuizen9-Jul-23 3:50 
Questionclosing serialport1 form 1 and form 2 Pin
geomeo12323-Mar-23 13:58
geomeo12323-Mar-23 13:58 
AnswerRe: closing serialport1 form 1 and form 2 Pin
Graeme_Grant23-Mar-23 15:10
mvaGraeme_Grant23-Mar-23 15:10 
I can think of 2 possibilities:

1. Put the serial port code in a handler class that implements IDisposable and pass it to form2 in the constructor:
VB
Using serialHandler As New SerialHandler

    Dim form2 As Form2 = New Form2(serialHandler)

    form2().Showdialog()

End Using

The Dispose method on the SerialHandler will handle the closing of the serial port if not already closed and dispose of any object that may cause memory leaks.

The other benefit is that you have encapsulated serial port handling and simplified Form2's code.

Note: If not modal, then store a reference to SerialHandler in Form1 and manually call the Dispose method of the SerialHandler class when Form2 is closed - this will require listening for Form2 closing event.

2. Implement IDisposable in Form2 so that when the form is closed and disposed of, the same applies as the first case.

If it was me, I would use Option 1.

Graeme


"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee


modified 23-Mar-23 21:18pm.

GeneralRe: closing serialport1 form 1 and form 2 Pin
geomeo12323-Mar-23 16:10
geomeo12323-Mar-23 16:10 
GeneralRe: closing serialport1 form 1 and form 2 Pin
Graeme_Grant23-Mar-23 16:22
mvaGraeme_Grant23-Mar-23 16:22 
Questionchange new form in winforms process running by user Pin
Member 1235220616-Jan-23 2:02
Member 1235220616-Jan-23 2:02 
AnswerRe: change new form in winforms process running by user Pin
Dave Kreskowiak16-Jan-23 13:44
mveDave Kreskowiak16-Jan-23 13:44 
GeneralRe: change new form in winforms process running by user Pin
Member 1235220620-Jan-23 11:09
Member 1235220620-Jan-23 11:09 
Questionadd new row if not exist row in datagirdview1 Pin
Sufvan Adil 202315-Jan-23 15:25
Sufvan Adil 202315-Jan-23 15:25 
AnswerRe: add new row if not exist row in datagirdview1 Pin
Richard MacCutchan15-Jan-23 22:01
mveRichard MacCutchan15-Jan-23 22:01 
AnswerRe: add new row if not exist row in datagirdview1 Pin
Richard Deeming15-Jan-23 22:33
mveRichard Deeming15-Jan-23 22:33 
Questionvb.net chart axis.X only every 5th Label should be shown. Pin
JTrum9-May-22 4:11
JTrum9-May-22 4:11 
AnswerRe: vb.net chart axis.X only every 5th Label should be shown. Pin
Dave Kreskowiak21-Jul-22 8:33
mveDave Kreskowiak21-Jul-22 8:33 
AnswerRe: vb.net chart axis.X only every 5th Label should be shown. Pin
Gerry Schmitz22-Jul-22 5:05
mveGerry Schmitz22-Jul-22 5:05 
GeneralMessage Closed Pin
1-Mar-22 19:44
SteveButtler1-Mar-22 19:44 
QuestionI Need Help On Windows10 Pin
David_Vickers22-Dec-21 21:33
David_Vickers22-Dec-21 21:33 
AnswerRe: I Need Help On Windows10 Pin
CHill6023-Dec-21 5:32
mveCHill6023-Dec-21 5:32 
GeneralRe: I Need Help On Windows10 Pin
David_Vickers23-Dec-21 19:05
David_Vickers23-Dec-21 19:05 
GeneralRe: I Need Help On Windows10 Pin
Dave Kreskowiak24-Dec-21 4:55
mveDave Kreskowiak24-Dec-21 4:55 
QuestionReplace text with image in DataGridView Pin
Member 1524267116-Jul-21 19:40
Member 1524267116-Jul-21 19:40 
AnswerRe: Replace text with image in DataGridView Pin
Richard MacCutchan16-Jul-21 21:35
mveRichard MacCutchan16-Jul-21 21:35 
GeneralRe: Replace text with image in DataGridView Pin
Member 1524267117-Jul-21 14:10
Member 1524267117-Jul-21 14:10 
AnswerRe: Replace text with image in DataGridView Pin
Gerry Schmitz17-Jul-21 5:58
mveGerry Schmitz17-Jul-21 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.