|
No, it wont. The destructor will be called when the garbage collector is about to remove the object.
If you want some clean up in the object, let the class inherit the IDisposable interface. When you are done with the object, call the Dispose method to do the clean up.
A good way of disposing of objects is using the using keyword. That will create a try...finally block with the Dispose call in the finally part. That ensures that the Dispose method is always called, whatever happens.
Class A {
...
private void methodA () {
using (B b = new B()) {
...
}
}
}
Class B : IDisposable {
...
~B() {
this.Dispose();
}
public void Dispose() {
...
}
}
---
b { font-weight: normal; }
|
|
|
|
|
I have this:
internal enum WelcomeData { Language, NumCusAdult, NumCusUnder4, NumCusUnder9, NumCusSenior, TimerEnable };
Everytime I use the enum as index in an array I have to cast it as int:
Data[(int)WelcomeData.Language] = Language;
This is very annoying
how do i make the enum act as int?
thx thx
|
|
|
|
|
Emm, subclass the array and define an indexer that take in the enum type?
|
|
|
|
|
I need to customize my windows application install wizard so that it will a config text file. (something like a .ini). The user must input something during install, and the file will be created when installed.
How can i do that? Where can i find a complete tutorial on customizing installation?
|
|
|
|
|
Hi,
I'm writing a process manager as my first real 'project,' I've got all the info into a listview (including the pid) and a kill method that works if you manually enter the pid but how would I go about extracting the pid and passing it to the method based on which row has been clicked ?
TIA.
-- modified at 3:59 Sunday 26th February, 2006
|
|
|
|
|
if(listBox1.SelectedIndex >= 0)
{
string a = (string)listBox1.SelectedItem;
// do you stuff here to extract the pid from string a
KillDaProcess(pid);
}
or use SelectedItems and loop thru the items if you allow user to multi-select
|
|
|
|
|
Gah, I meant listview rather than box, sorry.
Though I tried something like that initially, but it just kept returning "System.Windows.Form.ListView + SelectedListViewItemCollection" and nothing much to do with whats actually in the table.
|
|
|
|
|
I've managed to get the name out of the first column using lstProcesses.SelectedItems[0].Text, just have to figure out how to get it out of the third column
|
|
|
|
|
if you use listview, there is a Tag property that let you... hmm.. tag an object to an Item or SubItem.
You can just tag the pid string to Item's Tag, or you can tag a class containing the pid string + other stuffs to the tag.
So once you are able to get the SelectedItem, just take the object from Tag and that will be your pid.
Array array = listView1.SelectedItems;
if(array.Count>0)
{
for(int i=0; i
|
|
|
|
|
Ah that works brilliantly, cheers man
|
|
|
|
|
Hi,
I have extended a DataGridView class to add some custom event handling. I have a number of TextBox columns. I trap a Key Event and put a specific column into Edit mode. However, after the user completes their update and presses "Enter", I need to direct the focus to a new cell. By default the EndEdit call seems to move directly to the cell below. How do I override this?
I need to move the focus to another cell in the same row. Does anyone have a code snippet?
|
|
|
|
|
I am using MS Visual C# 2003 with Net 1.1. I can't seem to figure out how to compile code on multiple files without compiler complaints. What am I doing wrong? Thanks ahead o' time.
From Morse code... to DNA. All the universe is code.
|
|
|
|
|
What do you currently have in the seperate file? What compile errors are you getting?
Wacky waving inflateable arm flailing tube man!
- Family Guy
|
|
|
|
|
Thanks for getting back so soon, Sean! I've tried with namespace and classes from the first Form1 file. No matter how I arrange them or no matter what I try, I get compiler complaints.
From Morse code... to DNA. All the universe is code.
|
|
|
|
|
I'm not sure what errors your getting but here is an example of using a seperate file:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SeperateFile.PrintMessage("Hi n' Stuff");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class SeperateFile
{
public static void PrintMessage(string message)
{
Console.WriteLine(message);
}
}
}
The example above assumes that the methods in your seperate file are static. If they are not you need to instantane the SeperateFile class:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SeperateFile obj = new SeperateFile();
obj.PrintMessage("Hi n' Stuff");
}
}
}
Does this help?
Wacky waving inflateable arm flailing tube man!
- Family Guy
|
|
|
|
|
Excellent! It's getting late here in California. I'll work with what you have given me tomorrow. Thanks again! You have been very helpful.
From Morse code... to DNA. All the universe is code.
|
|
|
|
|
I think I see my prob. Like you said... instantiate. That should do it, I think. I'll try tomorrow. Best Regards.... Mike
From Morse code... to DNA. All the universe is code.
|
|
|
|
|
I created a program which has a "Load Picture" button, and a Picture Box .Whenever I click a "Load Picture" button, it will show a Open File Dialog then selected file will load to a picture box.
My question is How I can make the picture loads to my Picture Box when User right click on a image file ---> Open With --> browse for my program.
Like Photoshop, you know, when you rigt click a image file ---> Open With ---> Photoshop --> then Photoshop will open with that image file.
Thanks !
|
|
|
|
|
When Windows tries to open a file with your application, it's simply calling your executable with the file path as an argument.
It's basically the same as dropping a file on your executable in a windows explorer window.
So you just have to handle the arguments you get at startup in your Main method.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
thank you so much .....! I understood and tried it ! Worked perfectly ... !
|
|
|
|
|
Hi,
I have a startPrint method that sends a String to a printer to print, this method was called my many threads many time within a short period, and the following exceptions occurs,
System.ComponentModel.Win32Exception: The handle is invalid
at System.Drawing.Printing.StandardPrintController.OnEndPrint(PrintDocument document, PrintEventArgs e)
at System.Windows.Forms.PrintControllerWithStatusDialog.OnEndPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at VWServer.PrintObject.startPrint(String PrintingString, String PrinterName)
is there a way to fix this such that .NET is able to handle the large amoung of printing?
Thanks alot
|
|
|
|
|
Can I get rid of the class modifier 'S' in the following?
public class S {
public static string MyMethod( args ) { // foo }
}
public class C {
string s_answer;
s_answer = S.MyMethod( "bar" ); // how can I just write MyMethod()
}
Can I use a 'using' statement or some other directive?
Thx.
|
|
|
|
|
nyc_user wrote: Can I use a 'using' statement or some other directive?
No. In static methods you need to provide a class name where they belong to.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Unless, of course, you are calling it from within the same class the static is defined. (Sorry, I'm in a pedantic mood)
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Colin Angus Mackay wrote: you are calling it from within the same class the static is defined.
Or a nested class or an inherited class
|
|
|
|