|
And the string value for the Label.Text property in Windows Forms is dropped into the source code as well. Expand the "Windows Form Designer generated code" region and you'll see it. And if something doesn't appear in source code (like images in an ImageList or for any BackgroundImage properties, etc.), then it's most likely serialized to a ResX file. There's actually no hidden code like there was when designing forms in Visual Basic 6 and older.
But what does this have to do with "multi-styled lable" as you mentioned in your subject?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You didn't understood my question ...
ASP.NET Label.Text = "[b]Boldpart[/b]la[i]italic[/i]" gives (of course I know that it is < instead of [):
Boldpartlaitalic
Same manipulation can be done with fore color with is basicly what I need.
Now I was just wondering if there is a way to do that with "Windows Forms Label"... for example, \n will gives new line \t tab... is there something like that for color and bold/italic or should I go with developing my own Label that will have this?
|
|
|
|
|
pekica wrote:
You didn't understood my question
Actually, you really didn't explained what you want (which I mentioned in my first reply).
No, there is no style formatting specificiers and the Label wouldn't support them even if there was. It's a simple Static common control. Even extending it won't do much good because of that fact (it's limited to what the Static common control can do). You could always owner-draw your Label derivative, but that could be difficult.
Instead, you might consider just using a read-only, borderless RichTextBox . While RTF formatting isn't quite as simple as HTML formatting elements, it's not very hard and - if you wanted - you could always extend it to accept HTML format elements and transform them to RTF. Use the RichTextBox.Rtf property, though, not RichTextBox.Text .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
pekica wrote:
You didn't understood my question
Actually, you really didn't explained what you want (which I mentioned in my first reply).
Don't get to hard on me
In any case thanks again, you were helpful as always...
c-ya
|
|
|
|
|
I am involved in a project in which I should send bunch of requests(say around 50) to the server all of which are sent to the same domain. So, it's actually much faster to do this job through multi-threading, that is, I give the responsibility of requesting each URL to one separate thread. Requesting all the URLs in a single thread is actually done with no problem, But in multithreaded approach, I encountered some strange exception thrown while creating a WebRequest thru line below:
_URLReq = (HttpWebRequest)WebRequest.Create(_url);
_URLRes = (HttpWebResponse)_URLReq.GetResponse();
this is the exception that I receive:
The remote server returned an error: (403) Forbiddern.
There is no shared resource there, the only thing shared is Create method of WebRequest class which is a static method claimed to be thread safe. I speculated that it's the problem of that method, so I locked it:
lock(typeof(WebRequest))
{
_URLReq = (HttpWebRequest)WebRequest.Create(_url);
}
but it again didn't work. I locked the next line too:
lock(typeof(WebRequest))
{
_URLReq = (HttpWebRequest)WebRequest.Create(_url);
_URLRes = (HttpWebResponse)_URLReq.GetResponse();
}
And that exception never got thrown, the problem was solved. So, what should I say? It really doesn't appear to be thread safe. Any idea? 
|
|
|
|
|
The WebRequest.Create method is thread-safe because it's static. Statics are always thread-safe within an application domain (which goes without saying since threads exist in but one application domain).
The problem is with WebRequest.GetResponse . This should also be obvious since synchronizing the call eliminated the problem.
Since HTTP error code 403 actually describes many different errors, the most likely problem is that too many requests were made on the server and error code 403;9 (Too many users) was returned. You should trace the HttpWebResponse.StatusDescription in addition to the HttpWebResponse.StatusCode .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Your answers are always excellent Heath, thank you ![Rose | [Rose]](https://codeproject.freetls.fastly.net/script/Forums/Images/rose.gif)
|
|
|
|
|
Is it possible to use a vertical font in the header of a data grid? When the column titles ae longer than the contents of the cells, it seems such a waste of screen space to have wide columns (and not user-friendly to hide most of the titles by having narrow columns).
Any ideas welcome!
|
|
|
|
|
The DataGrid does not allow you to draw the column headers. I would recommend a third-party control like XtraGrid from Developer Express[^] if you require such functionality. Many third-party controls like those from Developer Express are cheap and most often royalty free.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Does anyone know how to develop a toolbar that doesn't steal focus from the foreground window?
For example:
In Visual Studio .NET, undock a tool window and then click on one of the buttons on the main window toolbar. Notice the tool window continues to have focus.
I want to do the same thing as Visual Studio. Currently I am using the Windows API ToolbarWindow32 class and the rebar control.
Cheers
David
|
|
|
|
|
hi
does any one know how can i convert this code that is made by C++ in dll to C# also to be put in dll
<br />
#define DllExport __declspec( dllexport )<br />
HHOOK h;<br />
DllExport extern LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam)<br />
{<br />
<br />
switch(nCode)<br />
{<br />
case WM_SIZING:<br />
return 0;<br />
break;<br />
<br />
case WM_MOVING:<br />
return 0;<br />
break;<br />
<br />
default:<br />
return CallNextHookEx(h,nCode,wParam,lParam);<br />
}<br />
}<br />
DllExport extern void InstallHook()<br />
{<br />
h=SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,0,0);<br />
}<br />
|
|
|
|
|
There's three types of ways to handle Windows messages in .NET:- Override the
WndProc method of a control (including Form , which derives from Control ). The Message structure contains the necessary information. You can use the Marshal class and the GCHandle structure to assist with marshaling the WPARAM and LPARAM . This is a Window hook. - Implement
IMessageFilter and add it to the collection of message pump filters using Application.AddMessageFilter . This is an application hook. - Finally - and you should be very careful and write good, efficient, error-checking code - are global system hooks like
WH_CALLWNDPROC . See the article Global System Hooks in .NET[^] for more information Decide whether you really need a global hook that applies to all Windows though. Using any language, this can decrease the performance and stability of Windows, but using a managed language will definitely decrease performance because of the runtime. In most cases, this is not necessary.
Just today I recommended handling these very notification messages by simply overriding WndProc on a form to prevent it from being moved or resized. This would be the most efficient way and would not affect other applications.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi guys
Now a days I am working with assemblies in .NET using C# and there is a problem
I want to get access specifier ie whether the field, method etc is public , private or protected, and the comments about that method or field using Reflection Namespace just like it is done in object browser of Visual studio.NET.
How to do that
Thanks
zaeny

|
|
|
|
|
Read the documentation for the classes in System.Reflection , and the topic Discovering Type Information at Run Time[^].
This forum isn't the place for article-length discussions. You can learn what you need to know from the information above, and you can additionally search CodeProject for many samples, but it really isn't that hard. At least reading that link will give you a good idea of where to start, but reading more about the classes in the System.Reflection will teach you more.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a ListView that contains the subfoldes of a local drive.
Whan i click on a subfolder the listbox should display the subfolders of
this folder instead.
the funktion is as follows:
private void FolderList_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
ListView.SelectedListViewItemCollection SelectedDir = this.FolderList.SelectedItems;
foreach ( ListViewItem Dir in SelectedDir )
{
FolderList.Items.Clear();
foreach (string d in Directory.GetDirectories(Dir.Text))
{
FolderList.Items.Add(d);
}
}
}
catch
{
MessageBox.Show("Error entering directory","Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
Now when i try to access the folder "System Volume Information" I first get
my MessageBox and then a messagebox saying that I have an unhandled
exeption.
But the funny thing is that I only get this message in the release version.
Can annyboddy tel me what I do rong?
The exeption text is as follows:
************** Exception Text **************
System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values.
Parameter name: '5' is not a valid value for 'displayIndex'.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32
displayIndex)
at System.Windows.Forms.ListView.LvnBeginDrag(MouseButtons buttons,
NMLISTVIEW nmlv)
at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
|
|
|
|
|
|
Hallo...
I'm here to ask you - maybe - a strange info.
My program runs in background and check every s second the processes list to see if some process is started while it is running. If the process is not known my app should prompt an advice asking what should it do with this process.
The problem is: how can I stop/block etc... windows until user answer the msgbox? I need to stop windows to prevent viruses or trojan execution.... like anti-virus apps do: when the antivirus dialog box is shown the process is refearing to can't continue its execution...
I hope I was clear
thenk you
Comet
|
|
|
|
|
That is not how an anti-virus application works. It doesn't monitor processes - it monitors file accesses so it will scan an executable before it's ever launched. Since you're not preventing a process from being launched, the chances are high that the machine was already infected.
I understand that you're not writing AV software (because if you were you really should understand how this stuff works first), but this is how the execution of the application is prevented - because it actually hasn't started yet. Once the application is started there's not a lot you can do that is *safe*.
A very simple way would be to display a system modal Form (set TopMost to true ) that is the size of the desktop working area (see SystemInformation.WorkingArea ) and that can't be moved (override WndProc in your Form , watch for the WM_SIZING message (0x0214), and set Message.Result to newIntPtr(1) , then call base.WndProc ). WndProc should look something like this:
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0214 || m.Msg == 0x0216)
m.Result = new IntPtr(1);
base.WndProc(ref m);
} This would prevent users from resizing or moving the window.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, you are right, i'm not writing an AV app. However I've never thought to file-access. I have 2 simple - I hope - questions:
1. where can I find more infos on how AV works??
2. The problem in my app is not about the app's window. I'm going to try to explain - hope quickly - how it should work:
- monitoring processes
- at first start collect processes "safe"
- monitor loop:
- if a process that is not known by my app is trying to start it should prompt if this process is safe - if so - it will be added to the "safe list" otherwise it should be closed or removed.
as you can see the problem is that when the process starts - as you wrote - it's too late to kill or close it.
strange app this ??
Ciao
Comet(italy)
|
|
|
|
|
_Comet_Keeper_ wrote:
1. where can I find more infos on how AV works??
There's no compedium of information about this. This is the result of years of research and experience into computer science and in-depth knowledge of the operating system you would target.
_Comet_Keeper_ wrote:
it's too late to kill or close it.
No it's not. Call Process.CloseMainWindow followed by Process.Close to exit the process gracefully, or Process.Kill to end the task.
Seriously, though, it sounds like you're trying to write AV-like software, where users are prompted if an unapproved application is started. First of all, 99% of users don't know what 99% of the processes are their system are. Many processes are Windows Services. Many processes run periodically to maintain the system. You're expecting too much of your clients. Besides, if you are going to right this type of management software, you should have more in-depth knowledge of the operating system.
For example, if you understand Windows Hooks, you can hook messages like WH_CBT to know when Windows are created. While you can do this in C# (search for "Windows Hooks" in the C# category here at CodeProject), it's very inefficient and you should definitely think about performance when righting such hooks (no matter what language you use).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i'm needin' a function that will take the following as parameters and output a string in the following format please help
<br />
int which_card = 0;
string bitsORbytes = "bits";
int upORdown = 0;
<br />
public int bandwidth_stat_info(int which_card, string bitsORbytes, int upORdown)<br />
{<br />
<br />
return data;
}<br />
thank's for the help ahead of time, i've been working on this project for almost 2 weeks now (a informative screensaver that displays certian data about your computer and it is fashionable too)
agian thanks your help it truely needed
|
|
|
|
|
You should take a look into performance counters. See the PerformanceCounter class documentation in the .NET Framework SDK, as well as the following articles that give a conceptual overview:Many of these statistics are already captures for you, so instantiating a PerformanceCounter around networking counters will give you these stats already. This is by far the simplest way in .NET to get these statistics.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm sort of new to C#.
I have had plenty of experience with Java, C, C++, you name it. C# is still a bit new to me.
My problem is this..
I am badly in need of a way to call a function from the Child to the Parent. The parent has the instance, so I'm not sure how to do this. Even if the function is public in parent, it doesn't seem to matter. I can't call it. I figure the answer lies with event handling, but I'm not sure how to set it up exactly. Can anyone help me out?
|
|
|
|
|
Try using the Parent or ParentForm propeties.
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
If the "Child" you refer to is in the "Parent"'s Controls collection, then use the Parent property (as the other reply stated), but you must cast the return value to your "Parent"'s class. The Parent property, for example, returns a Control . Your "Parent" derives from that (if you're talking about controls for child and parents, that is), but your method is not defined on the Control class, is it? It's defined on your class. In C#, you can use the keyword as to perform a safe cast, so that if the type isn't valid an InvalidCastException is not thrown, like so:
MyForm form = this.Parent as Myform;
if (form != null) form.SomeMethod();
Microsoft MVP, Visual C#
My Articles
|
|
|
|