|
Public Event Buttonclicked(MessageBoxNumber As Integer,
OKButton As Boolean, CancelButton As Boolean,
ExitButton As Boolean)
...becomes...
public event ButtonClickedEventHandler ButtonClicked;
protected void OnButtonClicked(ButtonClickedEventArgs args)
{
if(ButtonClicked!=null)
ButtonClicked(this,args);
}
To raise the event:
OnButtonClicked(new ButtonClickedEventArgs(messageboxnumber,
Then outside your class, you will need:
public delegate void ButtonClickedEventHandler(object sender, ButtonClickedEventArgs e);
public class ButtonClickedEventArgs : EventArgs
{
int m_MessageBoxNumber=0;
bool m_OKButton=false;
bool m_CancelButton=false;
bool m_ExitButton=false;
public ButtonClickedEventArgs(int messageboxnumber,
bool okbutton,bool cancelbutton,
bool exitbutton)
{
m_MessageBoxNumber=messageboxnumber;
m_CancelButton=cancelbutton;
m_OKButton=okbutton;
m_ExitButton=exitbutton;
}
public int MessageBoxNumber
{
get
{
return m_MessageBoxNumber;
}
}
public bool CancelButton
{
get
{
return m_CancelButton;
}
}
public bool OKButton
{
get
{
return m_OKButton;
}
}
public bool ExitButton
{
get
{
return m_ExitButton;
}
}
}
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Why 1 vb6 short code, in c# i need to code so much?
Any idea?
Regards,
Chua Wen Ching :p
|
|
|
|
|
The C# way of doing it has many advantages, icluding:
* You can assign lots of different events to the same method.
* You can very easily hook and unhook events at runtime.
* The C# event implementation is much more flexible.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
VB is meant for RAD which mean they ignored details for you. Good for general purpose programming, bad for advanced.
|
|
|
|
|
As for question #2:
In C#, a property set is the same as a property let - and that's how things should be.
You cannot pass arguments to a property. You can, however, use indexers or a method.
And question #3:
Try casting the values to integers after performing division on them.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
For question 2, i got an error:
This is how i code:
public string SmallWindowPrompt(int SmallWindowNumber, string vData)
{
get
{
return this.SM[SmallWindowNumber];
}
set
{
SM[SmallWindowNumber] = vData;
}
}
When i compile, it says i need to place 2 semicolons right after get and set.
I just change the variable name, but it is based on question 2..
any help?
Thanks for everyone replies.
Regards,
Chua Wen Ching :p
|
|
|
|
|
In C#, properties cannot have arguments. But why not just publicly expose whatever that SM collection is, and therefore eliminate the need for that property?
BTW, here's a tutorial[^] on properties in C#.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Hi. My English not that good.. what you mean by:
why not just publicly expose whatever that SM collection is
???
Can show me an example?
Regards,
Chua Wen Ching :p
|
|
|
|
|
Make a property for the SM collection.
public type SmallWindows
{
get
{
return SM;
}
}
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Another way: You can make this an overloaded method or create two properties.
public string SmallWindowPrompt( int smallWindowNumber ) {
return this.SM[sallWindowNumber];
}
public void SmallWindowPrompt( int smallWindowNumber, string vData ) {
SM[smallWindowNumber] = vData;
}
public string GetSmallWindowPrompt {
get { return this.SM[SmallWindowNumber];}
}
public string SetSmallWindowPrompt {
set{ this.SM[SmallWindowNumber] = value;}
}
|
|
|
|
|
Question #3
The dividion operator is overloaded to handle both integer and floating-point division.
Search for "Operators Compared in Different Languages" in the Help topics.
cast the results to integer.
float i = 1199282.293F;
float j = 199.33F;
newResult = (int)( i / j );
|
|
|
|
|
I have created a .dll file to manage data with an sql server.
I want to build a new windows app that uses that .dll
2 Questions:
1. Where does the .dll file go? In the same directory as my project?
2. When I include the file, is it just like I define other classes?
Using namespace.class;
|
|
|
|
|
Assuming you are using Visual Studio.NET, open the solution explorer and right click on the "references" folder, select the "Add reference" menu choice, then click the browse button. Browse to your .DLL file, and click "OK". That will add a reference to your .DLL to the project. From there, just add a line at the top of your source file like this:
"using mynamespace;"
Martin Cook
Who needs cyberspace when you have CP space?
|
|
|
|
|
Thank you , .. as for .NET classes, they should automatically reference .. is this correct?
I had a problem where I created an app that would not run on another system which didn't have VS.NET installed.
It was an XP Pro box with .NET1.1 installed.
|
|
|
|
|
I had a problem where I created an app that would not run on another system which didn't have VS.NET installed.
As long as the target machine has the .NET framework installed, you should be good to go. Ensure that the framework version on the target machine is the same as the one you compiled your application to.
|
|
|
|
|
Hey,
How do you hide a form on startup so that it doesn't show at all. I want to hide a form initially until the user clicks on a notifyIcon. Currently...
public Form1()
{
InitializeComponent();
this.Hide();
}
...does not work. Any suggestions?
-- Adam
"If you can't beat your computer in chess, try kickboxing"
|
|
|
|
|
Hey Adam,
try this, to prevent the form to be created at startup, if the no-button is clicked.
if (MessageBox.Show("Start Application",
"Question",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information) == DialogResult.Yes)
{
Application.Run(new Form1());
}
Maybe it's helpful...
Jörg
|
|
|
|
|
why not set a madule main function to be startup rather than a form. then you can do what you want with it
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Okay,
I've got a semi working solution, tell me if i'm doing anything that could lead to problems later.
public class Class1
{
static void Main()
{
Form1 form = new Form1();
Application.Run();
}
}
public class Form1 : System.Windows.Form
{
public Form1()
{
IntiallizeComponent();
this.Visible = false;
}
}
This creates the notifyIcon in the system tray, but does not show the form. When the notifyIcon is double clicked, then the form pops up. When the form is disposed, i have it call Application.Exit() so that the Application quits properly...this is mostly what i'm concerned about, that the tread is terminating properly.
-- Adam
"If you can't beat your computer in chess, try kickboxing"
|
|
|
|
|
I have a window with AutoScroll set to true, but I seem to have some odd problem wtih it.
Whenever the window gets focus, the scrollbars jump to 0. How can I fix this?
|
|
|
|
|
There is a property called AutoScrollPosition which contains the offset of the scrollwindow. I guess you have to manually account for this all the time...
But I really don't know cause I have the same problem.
If you find a good solution please let me know...
|
|
|
|
|
Hi guys !
Is there a way to know on which column of a ListView control the user has clicked ?
We can now the row but not the column.
Any idea ?
Thanks.
|
|
|
|
|
aeros,
you can do it through OnMouseDown (or OnMouseUp). That events have MouseEventArgs parameters X, Y which you can use in ListView GetItemAt method. GetItemAt gives you the clicked ListViewItem. And thanks to Index property you can obtain the column.
Hope it helped.
Tomas Rampas
------------------------------
gedas CR s.r.o.
System analyst, MCP
TGM 840,
293 01 Mlada Boleslav,
Czech Republic
Telefon/phone +420(326)711411
Telefax/fax +420(326)711420
rampas@gedas.cz
http://www.gedas.com/
------------------------------
|
|
|
|
|
Hi,
It doesn't work because ListViewItem.Index property gives you the row not the column.
--
Regards,
Julian.
|
|
|
|
|
You are right. We have to help ourselves with interop:
class YourClassName<br />
{<br />
const int LVM_FIRST = 0x1000;<br />
const int LVM_GETSUBITEMRECT = (LVM_FIRST + 56);<br />
const int LVIR_BOUNDS = 0;<br />
const int LVIR_ICON = 1;<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
struct RECT<br />
{<br />
public int left;<br />
public int top;<br />
public int right;<br />
public int bottom;<br />
};<br />
[DllImport("user32.dll")]<br />
private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, ref RECT lParam );<br />
<br />
private void listView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
RECT myrect;<br />
ListViewItem lvitem = listView1.FocusedItem;<br />
int wParam = lvitem.Index;<br />
int intLVSubItemIndex;<br />
ListViewItem.ListViewSubItem LVSubItem = null;<br />
int intSendMessage;<br />
<br />
for( intLVSubItemIndex = 1; intLVSubItemIndex < lvitem.SubItems.Count; intLVSubItemIndex++)<br />
{<br />
LVSubItem = lvitem.SubItems[intLVSubItemIndex];<br />
myrect = new RECT();<br />
myrect.top = intLVSubItemIndex;<br />
myrect.left = LVIR_BOUNDS;<br />
intSendMessage = SendMessage(listView1.Handle, LVM_GETSUBITEMRECT, wParam, ref myrect);<br />
if( e.X < myrect.left)<br />
{<br />
LVSubItem = lvitem.SubItems[0];<br />
intLVSubItemIndex = 0;<br />
break;<br />
}<br />
else if(e.X >= myrect.left && e.X <= myrect.right)<br />
{<br />
break;<br />
}<br />
else<br />
LVSubItem = null;<br />
}<br />
<br />
if (LVSubItem != null && lvitem != null)<br />
{<br />
MessageBox.Show(String.Format("ColumnIndex: {0} {1}", intLVSubItemIndex,<br />
LVSubItem.Text));<br />
}<br />
<br />
<br />
}<br />
}<br />
In the intLVSubItemIndex you have 0 base index of clicked column.
Tomas Rampas
------------------------------
gedas CR s.r.o.
System analyst, MCP
TGM 840,
293 01 Mlada Boleslav,
Czech Republic
Telefon/phone +420(326)711411
Telefax/fax +420(326)711420
rampas@gedas.cz
http://www.gedas.com/
------------------------------
To be or not to be is true...
George Bool
|
|
|
|