|
Thanks for your answers, you have given me some new ideas to try out. However I have another problem now. When the app is to execute, I get an exception :-/
The exceptions says "Error creating window handle" at the Application.Run(); in main. It didn't yesterday
|
|
|
|
|
Ah, solved it... my misstake
|
|
|
|
|
Hello..
I want to make Directory Dialog Box not File Dialog Box..
(It means I want get Directory name When I select Directory name in the dialog. You Know!!)
However I hardly know How to make it.
Is there anyone can help me?
Thanks..
I'm not who I was
|
|
|
|
|
Using the .Net 1.1 SDK you can just use the
System.Windows.Forms.FolderBrowserDialog.
If you are using the 1.0 SDK you can inherit from
System.Windows.Forms.Design.FolderNameEditor.
This implementation will most likely require that you use a
FolderNameEditor.FolderBrowser.
I have a class already written that can do this job if you like.
Also, I think there is at least one implementation posted here on CP.
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|
|
By using FolderNameEditor class and FolderBrowser class u can make Directory Dialog Box.
public class DirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
public string DirectoryPath
{
get
{
return strDirectoryPath;
}
}
public DirBrowser() { }
public DialogResult ShowDialog()
{
fb.Description = "Choose Directory";
fb.StartLocation = FolderBrowserFolder.MyComputer;
fb.Style = FolderBrowserStyles.RestrictToFilesystem;
DialogResult dlgResult = fb.ShowDialog();
if (dlgResult == DialogResult.OK)
strDirectoryPath = fb.DirectoryPath;
else
strDirectoryPath = "";
return dlgResult;
}
private string strDirectoryPath = "";
}
Instaniate DirBrowser class, call ShowDialog function and use DirectoryPath property to get the directory path :-
DirBrowser obDirBrowser = new DirBrowser();
obDirBrowser.ShowDialog ();
txtLogFilePath.Text = obDirBrowser.DirectoryPath ;
Chito.
|
|
|
|
|
http://www.codeproject.com/cs/miscctrl/folderbrowser.asp[^]
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi guys,
I want to change title bar color, but I am doing something wrong. So please, if anybody knows what it is, it would be good to let me know.
I declare:
using System.Runtime.InteropServices;
then I import API:
[DllImport("user32.dll")]
public static extern int SetSysColors(int nChanges, int lpSysColor, int lpColorValues);
[DllImport("user32.dll")]
public static extern int GetSysColor(int nIndex);
and then I call it this way:
int iRes = GetSysColor(4);
MessageBox.Show("Result: " + iRes.ToString());
iRes = SetSysColors(0, 4, 14898176);
MessageBox.Show("Result: " + iRes.ToString());
The first message box returns 16777215 which is a color of the menu (number 4 is the constant for menu), so it means GetSysColor function works, but the second function returns 0, which means it failed, and color of the menu does not change.
Why is that? Am I missing something obvious?
Thanks for your answers.
.
|
|
|
|
|
You have two problems. Firstly, the first parameter to SetSysColors is the number of colours you are changing, so it should be 1 instead of 0. Secondly, the second and third parameters should be passed by reference rather than by value (they are actually both pointers to the first element of an array). Changing the declaration to
[DllImport("user32.dll")]<br />
public static extern int SetSysColors(int nChanges, ref int lpSysColor, ref int lpColorValues);
and the call to
int iElement = 4;<br />
int iColor = 13160660;<br />
iRes = SetSysColors(1, ref iElement, ref iColor);
should make things work.
Chris Jobson
|
|
|
|
|
Yes, that worked, the problem was in passing the parameters.
Thanks man.
.
|
|
|
|
|
Hi Everyone,
Forgive the "1st Year Question" but, I have been struggling with this for a few days.
I am trying to build a SQL statment depending on if a Field is Empty of not.
This is the code that I am having trouble with.
It Compiles but it never gets to the "else if" statment.
I have an warning "Unreachable Code Detected" under "this" on the line that builds my sql statment.
[code]
if(("@LName" != "") && ("@City != ""))
{
this.sqlSelectCommand1.CommandText = "Select * from db where name LIKE @LName + \'%\') AND (city = @City) ORDER 5. BY name";
}
else if(("@LName" != "") && ("@City == ""))
{
Here--->this.sqlSelectCommand1.CommandText = "Select * from db where name LIKE @LName + \'%\') ORDER BY name";
}
[end]
Can Anyone tell me what is going on. Or if there is a better way of building SQL statments depending on the Data Entered?
Thank, Vinkoval
|
|
|
|
|
Is some code missing there? You are comparing one string literal to another, so the compiler knows that "@LName" will never equal "" and "@City" will never equal ""* so the first block of the if..else will always be executed.
I expected to see some other code like, if(LName != "" && City != "") where LName and City are variables, THEN the code should work as you assume.
*actually, you have a compiler error there because of an unterminitated string constant.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank James,
I hate to be a bother, but....
I tried what you suggested and Im sure it would work if I did it correctly,
but it seems to have the same effect as before i.e Only the First bolc of if..else is executed.
If it wouldn't be too much trouble.. The code that was missing from my previous post is here : http://www.ubtanet.com/example/example.php[^]
If you or anyone else that might be able to help point out the error of my ways.. I would really apprciate it.
Thanks
Vinkoval
|
|
|
|
|
k, the problem is that your if is checking a general case before a specific one; which is why the first part is always executed.
Specifically:
if( ... && City != "" ) the block following this will always be executed, unless City == "" . The first block is executed even when City == null because null and "" are two different values so the first condition is met.
To correct this you need to switch the order of the two if statements. i.e. compare for null first, then compare for the empty string.
HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Every different class/struct/whatever returns a unique Type class with the GetType() function, right?
Even when the object is cast into Object, it still returns the previous one, right?
Now how do I see if that type is derived from some other thing?
For example, if I have Object o and I need to see if it derives from ISomething interface.
If System.Type is not for this and does soemthing completely different, what way could I do this?
|
|
|
|
|
To test if an object implements an interface or derives from a type:
if( theObject is ISomething )<br />
{<br />
<br />
}
or
ISomething something = theObject as ISomething;
In the latter something will set to null if theObject doesn't support the interface
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Ah, thank you.
But how would I take the y in x is y from a variable?
I mean a type that the variable stores.
Something like this:
??? aaa = ???System.Exception // Checking against System.Exception for example
if (blah is ???aaa)
|
|
|
|
|
As Andres pointed out you can use the is/as statements to determine whether an object can be cast to the specified type name. In this case you use the name of the type, not the Type object representing that type. So for this to work you have to be able to reference the typename at compile time.
If the types are loaded at runtime then you can't use the above methods, instead if you have two Type objects, one from each of the two variables then you can use something like this.
bool IsBDerivedFromA(object a, object b)
{
Type ta = a.GetType();
Type tb = b.GetType();
return tb.IsSubclassOf(a);
}
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I find IsAssignableFrom() better for most cases as it follows natural logic.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
IsAssignableFrom() better for most cases as it follows natural logic
Yep, I like that one better. I suggested IsSubclassOf because that was the only method I could remember while my MSDN was being laggy.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank you
|
|
|
|
|
Im so embarressed to ask this, but I've written a c# app which uses windows forms. Well when I first wrote the dlls I used the System.Console for debugging, now I can't get rid of the damn thing. Ive taken out all references to the Console class, how do I lose the System.Console window?
Thanks for tolerating a stupid question,
Ryan
|
|
|
|
|
Assuming you are building with Visual Studio.NET, right click over your project in the solution explorer window and select properties. When the dialog comes up just change the "Output type" to Windows Application.
|
|
|
|
|
Thank you so much, I knew I had to be spacing out!
Ryan
|
|
|
|
|
Is there any function equivalent to the VB function CType (it converts an expression into a type) in C#?
- monrobot13
|
|
|
|
|
Have you tried using the static class with Convert.ChangeType?
|
|
|
|