|
You can't make globals in VB.NET or C#. Instead, you can create a class with public, static variables. However, global variables are often a sign of bad design, consider your approach first.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi friends i am developing windows application . I have two combobox on form.
I added comboBox1_SelectedIndexChanged event for both combobox. In form load
i bind both combobox with ArrayList arr and arr2 object ..The problem is that when i give combobox1.DataSource = arr it call combobox1_SelectedIndexChanged event why it call .... i didn't call it...because i have diff functionality for combobox1_SelectedIndexChanged event and it call on form load when i give combobox1.DataSource and my logic is failed how to avoid this ......
Thanks and regards
|
|
|
|
|
This happens because when the combobox is populated, the first item is automatically selected, and therefore, the SelectedIndexChanged event is called. Use a boolean flag to prevent this from happening:
bool AllowSelectedIndexChange = true;
void Form1_Load()
{
...
AllowSelectedIndexChange=false;
combobox1.DataSource = arr;
AllowSelectedIndexChange=true;
...
}
void ComboBox1_SelectedIndexChanged(...)
{
if (AllowSelectedIndexChange)
{
}
}
Hope this helps,
DigitalKing
|
|
|
|
|
|
hi DigitalKing & yogsworld!
you can also try these options:
option 1:
void Form1_Load()
{
...
combobox1.SelectedIndexChanged -= new EventHandler(SelectedIndexChanged_Handler);
combobox1.DataSource = arr;
combobox1.SelectedIndexChanged += new EventHandler(SelectedIndexChanged_Handler);
...
}
option 2:
remove the attaching of the SelectedIndexChanged event handler in the InitializeComponent, then just do it in the Form1_Load after the setting of DataSource property of the combobox.
just alternatives instead of using a flag.
microsoc
|
|
|
|
|
Hi Guies,
I am working on one application which require a url get executed through
c# code.
How to do it?
Thanks in Advance
yuvaaaaaaa
|
|
|
|
|
Hi,
This will load the URL in the default web browser:
System.Diagnostics.Process.Start("http://www.codeproject.com");
|
|
|
|
|
I have a Common UI project that contains many commonly used controls and wrappers for Buttons, label, textbox, treeview, etc.
E.g. public class ButtonEx:Button { /*custom properties*/ }
When I work on actual projects, I add this CommonUI project to the solution as an existing project. How the heck do I get the Visual Studio to recognize my the common controls and display them in the Toolbar? I don't want to explicitely add the controls by right-clicking on Toolbar and selecting Add-Remove Tools as that will create a copy of my primary DLL in VS's temp location.
I can get all of my user-controls to show up in Toolbar by opening them in designer mode, and (re)building the solution. I just can't get controls NOT deriving from UserControl to show up. I've tried closing/reopening VS several times, but no luck.
Any suggestion?
Thanks,
- Malhar
|
|
|
|
|
how would i go about creating a one button app that would delete cookies, temporary ie files, history, and temp folder files for any profile in windows xp. i only have basic or beginner level c# knowledge so any help would be appreciated. thanks in advance, roger
|
|
|
|
|
You can delete files using the System.IO.File.Delete static method.
You can retrieve files in a directory using System.IO.Directory.GetFiles static method.
You can find out the path to certain system directories (such as temp directory) using System.Environment.GetFolderPath static method.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
When I came across the problem of clearing the IE history from a .net app, I searched for days before finding this solution.
It's not pretty, but it gets the job done. Yes, every line is required. Just call the ClearHistory method to do it.
Add these imports:
using System.Runtime.InteropServices;
using Microsoft.Win32; Then,
[StructLayout(LayoutKind.Sequential)]
private struct UUID
{
public int Data1;
public short Data2;
public short Data3;
public byte[] Data4;
}
[StructLayout(LayoutKind.Sequential)]
private struct STATURL
{
public int cbSize;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsUrl;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsTitle;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastVisited;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastUpdated;
public System.Runtime.InteropServices.ComTypes.FILETIME ftExpires;
public uint dwFlags;
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE")]
private interface IEnumSTATURL
{
void Next(int celt, ref STATURL rgelt, out int pceltFetched);
void Skip(int celt);
void Reset();
void Clone(out IEnumSTATURL ppenum);
void SetFilter([MarshalAs(UnmanagedType.LPWStr)] string poszFilter, uint dwFlags);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("3C374A41-BAE4-11CF-BF7D-00AA006946EE")]
private interface IUrlHistoryStg
{
void AddUrl(string pocsUrl, string pocsTitle, uint dwFlags);
void DeleteUrl(string pocsUrl, int dwFlags);
void QueryUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl, uint dwFlags, ref string lpSTATURL);
void BindToObject([In] string pocsUrl, [In] UUID riid, IntPtr ppvOut);
object EnumUrls { [return: MarshalAs(UnmanagedType.IUnknown)] get;}
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("AFA0DC11-C313-11D0-831A-00C04FD5AE38")]
private interface IUrlHistoryStg2 : IUrlHistoryStg
{
new void AddUrl(string pocsUrl, string pocsTitle, uint dwFlags);
new void DeleteUrl(string pocsUrl, int dwFlags);
void QueryUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl, uint dwFlags, ref STATURL lpSTATURL);
new void BindToObject([In] string pocsUrl, [In] UUID riid, IntPtr ppvOut);
new object EnumUrls { [return: MarshalAs(UnmanagedType.IUnknown)] get;}
void AddUrlAndNotify(string pocsUrl, string pocsTitle, int dwFlags, int fWriteHistory, object poctNotify, object punkISFolder);
void ClearHistory();
}
[ComImport]
[Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]
private class UrlHistoryClass { }
public static void ClearHistory()
{
UrlHistoryClass c = new UrlHistoryClass();
((IUrlHistoryStg2)c).ClearHistory();
}
Sorry for the long post.
Hope this helps,
DigitalKing
|
|
|
|
|
Also useful is clearing the RecentDocs list:
using System.Runtime.InteropServices;
...
[DllImport("shell32.dll")]
static extern void SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, IntPtr pidl);
[Flags]
private enum ShellAddToRecentDocsFlags : uint
{
Pidl = 0x001,
Path = 0x002,
}
public static void ClearRecentDocs()
{
SHAddToRecentDocs(ShellAddToRecentDocsFlags.Pidl, IntPtr.Zero);
}
|
|
|
|
|
thanks for the advice, but it seems a bit more advanced than what i can handle right now. maybe this scenario will be a little more simple and get me going in the right direction. say i want to delete a folder or file in any directory i chose, how would i go about that. i read something about a fileinfo.delete method, will this work. also, can you point me to any good texts about file,folder,directory handling in csharp. thanks again
|
|
|
|
|
I am developing an UI application for pocket pc. Two panels are overlayed, and each panel has two buttons anchored in. I want to use tab function to navigate among those buttons. As I use tab order, it shows buttons in one panel in the orde of 0.0, 0.1, buttons in another panel in the order 1.0, 1.1. How to use the parameters 0.0, 0.1 and 1.0, 1.0? Thanks.
|
|
|
|
|
How does one detect the current control the mouse cursor is over when one does a mouse button down and move? It appears that the control when the move started repeatedly fires its mouse move event but other controls are ignored. Do i have to do some kind of hit test? What is typically done in C#?
|
|
|
|
|
Greetings,
I'm in .NET 2.0
I'm working on an app where the Main Form contains a webBrowser Control. I do not want to show the Main Form until the document has completed loading in the web browser control or until 60 seconds has passed...in which case, I will then load an offline version.
The webBrowser control has a DocumentCompleted event. So that I know if it has finished loading. The problem is, I need to Load the url for the webBrowser control on a separate thread, and then loop for 60 seconds on the GUI Thread, or Until Ive been notified that the document has loaded. I have tried something like this....but I think the problem is that the webBrowser Control belongs to the GUI Thread.
public frmMain()
{
ThreadStart ts = new ThreadStart(DoWork);
Thread thread = new Thread(ts);
thread.Start();
for (int i = 0;i<60;i++)
{ if (m_documentLoaded)
{
i = 60;
}
else
{
System.Threading.Thread.Sleep(1000);
}
}
}
public void DoWork()
{
System.Uri url = new System.Uri("http://myDomain.com/default.aspx/");
webBrowser1.Url = url;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
m_documentLoaded = true;
}
I know what I want to Do...just not sure exactly how to carry it out...
Thanks for any input
|
|
|
|
|
Create a timer on your form with interval set to 60 seconds. Load the browser page on the UI thread, start the timer. When the timer tick event has been raised, check if m_documentLoaded is true, and if not, load the offline version.
|
|
|
|
|
Excellent.... once again...I was overthinking.
Thanks
|
|
|
|
|
Hi, I am using recursion to search for a folder in searchPath and if a subfolder or the searchfolder is the same as saveFolder(the
folder to copy the files to), it skips searching file in the saveFolder. Other than that, it keeps searching the file recursively and calls the
method this.SearchFile(..)
This obiviously fails to build because I didn't assign anyting to 'string folderName' and breaks the logic.
Can anyone please correct this method?
saveFolder path is at saveTextbox.Text
public void GetsubFolders(ref string searchPath, string fileName)
{
string[] folder = Directory.GetDirectories(searchPath);
string folderName;
int index = 0;
if (folder.Length !=0)
{
if (String.Compare(folder[index].ToString(), saveTextbox.Text.ToString()) == 0)
{
index++;
if (folder.Length == index)
{
return;
}
else
{
for (; index < folder.Length; index++)
{
folderName = Convert.ToString(folder[index]);
GetsubFolders(ref folderName, fileName);
}
}
}
else
{
for (; index < folder.Length; index++)
{
folderName = Convert.ToString(folder[index]);
GetsubFolders(ref folderName, fileName);
}
}
}
this.SearchFile(folderName, fileName);
}
|
|
|
|
|
How can I send a struct/class from client to server by using tcp/ip in c# ?
|
|
|
|
|
Hi TJVictor
Have a look at .Net remoting. I think that's the technology you're looking for.
For example:
http://www.codeproject.com/csharp/DotNetRemotingBasicTutor.asp[^]
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
I have read a lot of books on C#, but what I am ultimately looking for I have yet to find. 1st I would like a book on explaining good practice of creating classes and explains inheritence. Next, I would like a desk reference, with good explanations and examples ( unlike MS Documentation ) for C#.
Thanx in advance
Jude
|
|
|
|
|
I am dynamically connecting to an unmanaged C++ COM interface using GetTypeFromProgID, but I must get a secondary IDispatch interface by calling the "GetBasicCallInfoIDisp" function of that interface. Using this secondary interface, I am trying to get a simple property.
The JavaScript is very rudimentary:
var winoperdoc = new ActiveXObject("WinOper.Document");<br />
var winoper = winoperdoc.GetBasicCallInfoIDisp();<br />
window.alert(winoper.SeizureID);<br />
The C# version I have looks like this:
Type objWinOper = Type.GetTypeFromProgID("WinOper.Document");<br />
<br />
object objWinOperLateBound = objWinOper.InvokeMember("GetBasicCallInfoIDisp",<br />
BindingFlags.CreateInstance,<br />
null, <br />
objWinOper, <br />
new object[]{});<br />
<br />
int SeizureID = (int) objWinOper.InvokeMember("SeizureID",<br />
BindingFlags.Default | BindingFlags.GetProperty, <br />
null, <br />
objWinOperLateBound,<br />
new object[]{});<br />
This compiles, but I get an "Unknown Name" when I try to get the value from a member property.
Any help is appreciated.
Cheers,
Daaron
|
|
|
|
|
- how I can add more image in pictureBox ?
- how I can move image in pictureBox with mouse ?
|
|
|
|
|
You cannot add more than one image to a picture box. You can, however, add multiple picture boxes to another control such as a panel.
The picture box control doesn't contain any functionality for moving pictures within it. You can do this yourself by watching for when the user drags the mouse, then move the picture box itself.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|