|
Okay, with your idea, you can do the following when you create the buttons, assuming you have a Hashtable named buttonDict and an int named buttonIndex:
Button b = new Button();
b.Text = "Button " + buttonIndex.ToString();
buttonDict[ b ] = buttonIndex;
buttonIndex++; and, then, in your event handler
private void AllButton_Click( object sender, System.EventArgs e )
{
int clickedButtonIndex = -1;
if( buttonDict.ContainsKey( sender ) )
{
clickedButtonIndex = Convert.ToInt32( buttonDict[ sender ] );
}
} However, I think that you're keeping around a Hashtable for no reason. You could, alternatively, do the following in the place where you create your buttons:
Button b = new Button();
b.Text = "Button " + buttonIndex.ToString();
b.Tag = buttonIndex;
buttonIndex++; and in your general button click event handler:
private void AllButton_Click( object sender, System.EventArgs e )
{
int clickedButtonIndex = -1;
Button b = ( Button ) sender;
if( b.Tag != null )
{
clickedButtonIndex = Convert.ToInt32( b.Tag );
}
} I hope that answers your question sufficiently.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hello, everyone, I have and application that start when the windows(2000) start, every time that the application run read the directory and put it in the registry, i have installed the program in c:\safeupdate\directory.exe but when the application star with windows the directory is c:\documents and setting\administator\directory.exe WHY?, How can i obtain the real directory?, my code is the next:
Private void Form1_Load(object sender, System.EventArgs e)
{
string pathNow = Directory.GetCurrentDirectory()+@"\directory.exe";
Registry.LocalMachine.OpenSubKey(@"software\microsoft\windows\currentversion\run",true).SetValue("directory",pathNow);
}
I need the real directory because in the registry put the wrong directory and the next time won't run the application because doesn't exist inthe c:\document and setting\directory.exe, please help me.
Greetings from Tijuana Mexico
|
|
|
|
|
RobertoTjMx wrote: string pathNow = Directory.GetCurrentDirectory()+@"\directory.exe";
Try replacing the above line with the following:
string pathNow = Application.ExecutablePath;
Or, with the following:
string pathNow = Application.StartupPath + "\\directory.exe";
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Thanks, I solved my problem.
|
|
|
|
|
Application.StartUpPath
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
i try to make HttpWebRequest
with this code
----------------------
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.elections.ps/afindcenter.aspx");
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
-----------------------------
when i test it in localhost it work %100
but when i upload it to my host i recive this error message
***********************
Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
Source Error:
Line 36: // Set credentials to use for this request.
Line 37: request.Credentials = CredentialCache.DefaultCredentials;
Line 38: HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Line 39:
Line 40: // Get the stream associated with the response
Palestine
|
|
|
|
|
Can you give us more information about the host? Specifically do you know what process your app is running under? Also what is your relationship with the specified website?
CredentialCache.DefaultCredentials is essentially the credentials your application is running is. When you run it on your local box, this represents your credentials. If your host (I'm assuming it's a WebServer somewhere) is running as a completely different user so this would have a different value and explain why you are denied access
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
information about the host?
i use hostingrightnow.com hosting with .Net 2.0
relationship with the specified website?
no relationship but this web site any one can open it (normal web site) as yahoo gmail and in my local host i can open without any CredentialCache but i see it mircrosoft web site and in use it
Palestine
|
|
|
|
|
Tareq Abuzuhri wrote: my local host i can open without any CredentialCache but i see it mircrosoft web site and in use it
In this case, since the end result is that the app will be hosted on a web site you probably don't want to do this. All having that line does is enable NT and Kerberose authentication. Since this is a public website you don't need to add that line.
I'm not sure why you are getting that error then. The only explanation I can come up with is that http://www.elections.ps/afindcenter.aspx is actively denying your host. I don't know of any good way to determine if that is the case or not though.
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
On my form (MainWindow) I have a TabControl called MonitorTabs. I programmatically add a tab to it for each user I want to monitor. Then I add a user control called Monitor that contains a group of controls including a timer (RefreshTimer) to that tab.
From MainWindow, I call a function that needs to reset the interval on RefreshTimer on the currently selected tab. The number of RefreshTimers is dynamic, one for each User Control/Tab, and I don't know how to access any of them let alone the one that is currently selected. The timer is set to public, and still nothing shows up.
Can anyone help?
|
|
|
|
|
What you are asking is how to access the currently selected tab? If yes, the following line of code popups a MessageBox with the text of the currently selected tab:
MessageBox.Show(this.tabControl1.SelectedTab.Text);
If I understood otherwise, please try being a bit more specific with your question
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Sorry I wasn't clear enough.
On each tab is a user control called Monitor. So if I have three tabs, then there are three Monitors. Monitor has various elements including a timer, a datagridview, a treeview, etc... since they are part of the same user control, they are all named the same.
So for example, I want to set refreshTimer on Monitor on tab 2 (the currently selected tab). How would I access that refreshTimer.
I have tried the following without success
MonitorTabs.SelectedTab.Monitor.refreshTimer<br />
MonitorTabs.SelectedTab.refreshTimer<br />
MonitorTabs.TabPages[MonitorTabs.SelectedIndex].Monitor.refreshTimer
Thanks
|
|
|
|
|
Hmm... if I get it right, I would keep track of each Monitor's instance name on each tab (e.g. I would add "Monitor1" on tab1, "Monitor2" on tab2 and so on. Then, in order to access them, I would locate them by their names).
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
That makes sense but I've never tried that before (somewhat new at this), could you demonstrate please? This is my current code.
TabPage newMonitorTab = new TabPage(TabTitle);<br />
MonitorTabs.TabPages.Add(newMonitorTab);<br />
<br />
MonitorTab monitor = new MonitorTab();<br />
newMonitorTab.Controls.Add(monitor);
Thanks!
|
|
|
|
|
You could write something like this:
TabPage tab1 = new TabPage("Tab 1");
MonitorTabs.TabPages.Add(tab1);
MonitorTab monitor1 = new MonitorTab();
tab1.Controls.Add(monitor1);
TabPage tab2 = new TabPage("Tab 2");
MonitorTabs.TabPages.Add(tab2);
MonitorTab monitor2 = new MonitorTab();
tab2.Controls.Add(monitor2);
This way, you know that tab1 has monitor1 on it, and tab2 has monitor2. So if the selectedTab is tab1 then you access monitor1 by writing something like this.monitor1
Hope this makes sense.
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Its getting closer, I have added them and can access them to a point using the following:
MonitorTab monitor = new MonitorTab();<br />
monitor.Name = "Monitor" + MonitorTabs.TabPages.Count.ToString();
But I still can't access that control except using a foreach looping through the controls on the tab, which doesn't allow me to access the timer. Any suggestions?
|
|
|
|
|
You can also make an hashtable, like [Tab] - [Monitor]:
private HashTable monitors = new HashTable();
MonitorTab GetMonitor(TabPage tab) {
return (MonitorTab) monitors(tab);
}
void AddTab() {
TabPage newMonitorTab = new TabPage(TabTitle);
MonitorTabs.TabPages.Add(newMonitorTab);
MonitorTab monitor = new MonitorTab();
newMonitorTab.Controls.Add(monitor);
monitors.Add(newMonitorTab, monitor);
}
MonitorTab selectedMonitor = GetMonitor(this.tabControl1.SelectedTab);
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
That worked great! Thank you both! *sigh of relief*
|
|
|
|
|
Hi, can anyone help I need a string manipulation to do the same as Len(in VB) or strlen()in C as well as Mid$ in VB or strstr()in C. This is to allow me to pick off bits in a string to send them to the RS232
Doh!
-- modified at 15:17 Friday 9th December, 2005
|
|
|
|
|
|
I tried that it comes up with LEN which I can't get to work, or is it something like string.LEN, I am a little desperate!
Glenn
Doh!
|
|
|
|
|
What!? Where? No where in the linked page is there a LEN() or string.LEN
string myString = "Some text";
myString.Length
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
GlennP. wrote: I tried that it comes up with LEN which I can't get to work
What are you talking about? Where on the link I posted did it mention LEN? It did quite clearly mention Length and Substring which can be used in place of Len and Mid from VB. So what's the problem?
|
|
|
|
|
I am sorry I was using the MSDN that came with the version of .NET which is different from the from the online version, All I can say is a nights sleep is required at least once a week!! sorry!
Doh!
|
|
|
|
|
The one that can with Visual Studio .NET doesn't mention LEN either! Are you sure you were looking at the .NET version or the older VB6 version?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|