|
Use the form's SuspendLayout() and ResumeLayout() methods.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Hi All!
I've few queries regarding MS Word programming in C#. I need to open a word document (fetched from server) to perform few customize tasks in my client (c# based) and pushed back to server. Pls help me to know how to accomplish following stuff
1. Which activex control should be used... Can I use browser plug-in for this.
2. How to open a word document as read only (no editing should be allowed.)
3. How to open a document associating with a particular template (not the global one) if using a browser plug-in.
4. When a user inserts a comment, the user name that appears in the comment should be my application specific not of the Word application. As api supports this but the modified name should not be reflected in MS WORD.
I would really appreciate of any kind of suggestions.
Thanks In Advance
Bimpy
|
|
|
|
|
In C# it is not legal (or compilable) to let execution fall thru from one switch case context to another.
I'm working on a piece of code to do a MouseHook in C#. Becuase it has to deal with win 32 API messages, I of course have a big long switch statement or two.
An example is deciding which button spawned a particular message, based on the message ID.
In good-ol' C/C++ you'd do it something like this:
int button = 0;
switch ( wParam )
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
button = LEFT;
break;
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_RBUTTONDBLCLK:
button = RIGHT;
break;
} Well that won't compile in C# and given the nature of a C# switch statement I can see two alternatives.
MouseButton button = MouseButtons.None;
switch ( wParam )
{
case WM_LBUTTONDOWN:
button = MouseButtons.Left;
break;
case WM_LBUTTONUP:
button = MouseButtons.Left;
break;
case WM_LBUTTONDBLCLK:
button = MouseButtons.Left;
break;
case WM_RBUTTONDOWN:
button = MouseButtons.Right;
break;
case WM_RBUTTONUP:
button = MouseButtons.Right;
break;
case WM_RBUTTONDBLCLK:
button = MouseButtons.Right;
break;
}
or something like :
MouseButton button = MouseButtons.None;
switch ( wParam )
{
case WM_LBUTTONDOWN:
goto case WM_LBUTTONDBLCLK;
case WM_LBUTTONUP:
goto case WM_LBUTTONDBLCLK;
case WM_LBUTTONDBLCLK:
button = MouseButtons.Left;
break;
case WM_RBUTTONDOWN:
goto case WM_RBUTTONDBLCLK;
case WM_RBUTTONUP:
goto case WM_RBUTTONDBLCLK;
case WM_RBUTTONDBLCLK:
button = MouseButtons.Right;
break;
}
Realizing that big switch statements are notoriously buggy and difficult to maintain, I'm torn between which flavor is less bad.
We've all, of course, been schooled on the harmfulness of goto , and the poor person who's got to debug that code four years from now is in for headache.
On the other hand, without the goto's, you end up with a lot duplicate code (all the assignment statements in the above exaple), which always raises a red flag for me (especially because of the maintainance issues duplicate code can cause).
Anybody got an opinion on this? I'm leaning towards the non-goto version but am looking for other opinions.
Cheers,
don
|
|
|
|
|
I don't understand. Your example of stacking up case labels does compile in C#. Here's a small example:
Random r = new Random();
switch (r.Next(10)) {
case 1:
Console.WriteLine("It's one");
break;
case 2:
case 3:
case 5:
case 7:
Console.WriteLine("It's prime");
break;
default:
Console.WriteLine("It's composite");
break;
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
I was getting an error when I was setting up a switch block, and on further examination it looks like it was because I failed to include a break in my default case.
Without the break in the last case statement you get something like: "error CS0163: Control cannot fall through from one case label ('case 2:') to another"
However, when I first encountered the error I found this in the C# MSDN reference on the switch statement:
"Unlike the C++ switch statement, C# does not support an explicit fall through from one case label to another. If you want, you can use goto a switch-case, or goto default."
Now I'm confused, because that apparently doesn't mean what I thought it meant.
The way I read the statement from MSDN, plus if you read the help on error number CS0163 (see reference below), it seems to support my original post.
It seems like either the C# help is in error, or the compiler is in error (or I'm just plain missing something).
don
References
Error CS0163:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003JUL.1033/cscomp/html/vcerrCompilerErrorSC0163.htm
Switch statement help:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003JUL.1033/csref/html/vclrfTheSwitchStatement.htm
|
|
|
|
|
Ah ha! You're reading the "simplified" pages and I'm not surprised that you found ambiguity. Personally I tend to go to the authoritative source, the C# Language Reference. Here you see that
a switch statement consists of "switch" followed by an expression in parentheses followed by a switch block
a switch block consists of 0 or more switch sections, the whole wrapped in braces
a switch section consists of one or more switch labels followed by a list of statements
a switch label is either "case" followed by a constant expression followed by colon, or "default" followed by colon.
It is the statement list that cannot "fall through." (In fact, it's stated as "the end point of a statement list cannot be reachable," by which it means that you cannot get to the point just after the last statement in the statement list. In other words, the last statement in the list must be a "jump" type statement: break, goto, throw, etc.)
Hence, <phew>, you can have code that lokos like this:
switch (foo) {
case 1:
case 2:
DoSomething();
break;
...
}
As to the error message, I agree that it could be a little misleading, although it does correctly talk about the last switch label in the (possible) list of labels.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
And the light comes on!
It does makes sense now (and also renders my original post completely moot).
Thanks for clearing up the ambiguity for me Julian!
don
To summarize
legal:
switch case( foo )
{
case 0:
case 1:
DoIt();
break;
} not-legal:
switch ( foo )
{
case 0:
DoOneThing();
case 1:
DoAnotherThing();
break;
} also not legal:
switch ( foo )
{
case 0:
DoOneThing();
break;
default:
DoAnotherThing();
}
|
|
|
|
|
I found that GDI+ has some features for smoothing (SmoothingMode,TextRenderingHint...). MSVisio2002 also uses GDI+ (I suppose). But graphics in Visio and my GDI+ application looks different. It seems that Visio uses another smoothing mode, do you know which ?
|
|
|
|
|
MS used to have a thing called "Browser Helper Object", supporting IE4 (maybe 5). Is there a newer parllel to this? To be specific, I would like to gather statistics on my browser, such as download time of each object in a web page. Are there events raised by IE handling such questions?
at first stage, I don't mind activating the browser programmtically (I gather that the strongest feature of the Browser Helper was that it attached itself to any instance of the browser )
YD
|
|
|
|
|
Hi All,
Recently I loaded a C# project am writing using VS.Net 2002 all of a sudden the development enviroment closes my project by it self. It repeated several time any time I load the project and start coding.
I've even reinstalled VS.Net 2002 in an XP OS, tried to open the same project from another PC (Win2k Pro) having VS.Net 2002 . Visual studio.Net 2002
still close itself after allowing me to work for a while.
I am waiting for your sugestions or advice on what to do. I don't know wheather it is a bug with Visual Studio 2002.
Thanks
(I've posted the same question on Visaul studion IDE board)
|
|
|
|
|
Mmm...
Some tips, XP, XP Service Packs. something wrong with your version...
|
|
|
|
|
I've being using the Vs.net 2002 for about 8 months now. Apart from that, I've tried it in two different OS (XP and WIN2K Pro service 3). For now am even afriad opening it in any other machine running visual studio. I have scanned for virus. The file is not infested with virus. Or does there exist different version of VS.Net 2002?
|
|
|
|
|
Hi, i'd like to learn C#, any book titles suggestion!?
nevhile.net
|
|
|
|
|
Hi there,
I am learning too.
Programming C# 3rd Edition by O'REILLY is pretty good.
|
|
|
|
|
|
Wrox: Professional C# 2nd Edition is fantastic!
Mads
|
|
|
|
|
WebClient objClient= new WebClient();
objClient.DownloadFile("ftp://..../XXXX.txt","c:\\XXXX.txt");
|
|
|
|
|
hi guyz!
actually i have a datset in which i want to filter it according to some condition n then display the required value in the combobox , hope u could help me out , i will be looking forward to ur help thx buddies
Work Hard and Test your Luck
|
|
|
|
|
Use dataset.tables[index].Select to filter the dataset.
I think you should be able to databind the combobox to the dataset using one of it's properties in e.g. designview.
Mads
|
|
|
|
|
Hi everyone
How do get the listview control to force a multiple line display when the
column width is too small?
Anyone written an overide implementation on this? Some sample source will
be most helpful
Many thanks
bchong
|
|
|
|
|
Hi. I want to create a simple notepad.
I used a multiline textbox. I wanted to create a shortcut
for selecting all text in the textbox like pressing ctrl-A would
select all text. Anybody knows how to do this?
Please help me.
"To teach is to learn twice"
|
|
|
|
|
textBox.SelectionStart = 0;
textBox.SelectionLength = textBox.TextLength;
And who modded the parent posting up to 5???
--
-Blake (com/bcdev/blake)
|
|
|
|
|
You can also use textBox.SelectAll().
|
|
|
|
|
I'm new to the C# language, and my Java experience is foiling me here.
My application doesn't really have one main form--it has two (or at least I feel they should be peers). Exactly one of these two windows is visible at any one time, but I'd like the one that IS visible to operate as if it's the main form, in that clicking on the close box of the Form subclass will kill the application. By default, the Form passed to Application.Run(), if closed, kills the entire application. Is there any way to change the main form so that the entire application DOESN'T die just because I call Close() against it. My intent is to create a second (completely different) form, call Show() against it, and then Close() the original one. I could just set it to be invisible, but I'd rather dispose of it entirely and not have to maintain a reference to the Form just so I can call Close() against it when time comes to really kill the application.
Any advice?
|
|
|
|
|
Replace:
Application.Run(myForm);
with:
myForm.Show();
Application.Run();
Alternatively, derive from ApplicationContext and pass one of those into Application.Run(), that's what ApplicationContext's are for.
And don't worry, we won't hold the whole Java thing against you.
--
-Blake (com/bcdev/blake)
|
|
|
|