|
This isn't something you can just throw together with the designer, unless you've bought some expensive third-party control that does this for you.
It's quite simple, though. A good object-oriented design would place the Outlook-like sidebar on one side and a container (like a Panel on the other. For each clickable icon in your Outlook-like sidebar, you would implement a UserControl (for example - could be any Control derivative although a container control is typically best) in your project. You need to associate that control with your sidebar icon. You could store the Type in the Tag property (if applicable) for the sidebar icons, or use attributes or whatever.
When the icon is clicked, you create an instance of that Control (perhaps maintaining a Hashtable with types and instances so that you can simply reuse a previously instantiated instance) and parent it (i.e., use Pane.Controls.Add ) to the Panel on the other side. When a different icon is clicked, remove that Control (if an instance of it is still held - perhaps in that lookup table I mentioned above - it will remain in memory) using Panel.Controls.RemoveAt(0) (for example) and add the Control associated with the icon that was clicked.
This is really a simple OO design and there are many examples of similar designers here on CodeProject. I suggest trying a search or browsing the categories to read a few of these for specific details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey thanks a lot for your help! That was what I'm looking for! Would you say it is better to access the UserControls via:
Panel1.Controls(index)
or with a help-variable - such as:
private Control _ctl = null;
TextBox tb = new TextBox();
tb.Text = "Hi!";
_ctl = tb;
panel2.Controls.Add(_ctl);
??
on the second example: why some people write "this.panel2.Controls.Add(_ctl);" and not like I did in my example without this. ? Thx!!
- bb
|
|
|
|
|
You should really read the .NET Framework SDK documentation. Panel.Controls[index] (not parenthesis) is for accesing a Control based on its index. You can't add a control that way, nor can you set a control with a previous index (there is not set accessor defined for the Controls collection property - it's read only). You must use Panel.Controls.Add as you saw below.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Oh sorry - it was a missunderstud!
What I ment:
------------
TextBox tb = new TextBox();
tb.Text = "Hi!";
panel1.Controls.Add(tb);
//access via
panel1.Controls[index].blabla();
or with a help-variable - such as:
private Control _ctl = null;
TextBox tb = new TextBox();
tb.Text = "Hi!";
_ctl = tb;
panel2.Controls.Add(_ctl);
//access via
_ctl.blabla();
- bb
|
|
|
|
|
Either way works. What matters most is how often you plan on accessing the control. Repeated calls to panel2.Controls[index] require more instructions, so using a field or variable is a better choice.
Besides, you can't access it like panel1.Controls[index].blabla(); like you declared above. Panel.Controls[index] will always return a Control . You can only call methods or access properties declared on the Control class or inheritted from a base class. You must cast it to your class in order to call methods or use properties declared such as blabla() (for example). In this case, using a field would be easier but you don't need to pass TextBox to a Control like you're doing in your block:
private Control _ctl = null;
TextBox tb = new TextBox();
tb.Text = "Hi!";
_ctl = tb;
panel2.Controls.Add(_ctl);
_ctl.blabla(); TextBox derives from Control , therefore it is already a Control . Just use panel2.Controls.Add(tb) . That's polymorphism.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So you would say - this would be better:
--
private Control _ctl = null;
TextBox tb = new TextBox();
tb.Text = "Hi!";
_ctl = tb;
panel2.Controls.Add(tb);
//access via_ctl.blabla();
--
_ctl for better access (less instructions)
If this example would be "cleaner" what is in this case above the difference to ".Add(_ctl)"?
BTW: TextBox is just for this Example normaly I would add a UserControl *g*
- bb
|
|
|
|
|
Quit casting to Control . A TextBox derives from Control - all methods, properties, fields, and events (besides private members) are inheritted. A method that is declared on Control (like Text ) is accessible on TextBox :
TextBox tb = new TextBox();
panel1.Controls.Add(tb);
tb.Text = "Hi";
tb.Refresh(); It's still an instance of a Control , just a derivative of it. This is simple object-oriented development. For example, every type in .NET derives from Object , so every type inherits a ToString method, a GetType method, and more. Some may override the behavior of that member or even hide it (at design-time only), but the member is always defined for derivative types.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Oh I see!
Thx a lot for your good help!!
|
|
|
|
|
I'm working on an application that displays properties of an object in a PropertyGrid control. This object's properties don't have attributes (like BrowsableAttribute, CategoryAttribute, etc.). Since I want to control how and which properties are displayed in the PropertyGrid and in which categories and so on, I have made a "wrapper-class". It copies the required data from the original object and makes it accessible in custom properties which are not a one-to-one representation of the properties of the original object (instead they are split-up into more user friendly ones). The wrapper-object stores a reference to the original object as well. Some of these properties in my wrapper-class access objects which have properties themselves. With the use of the TypeConverterAttribute I am able to show and edit nested properties. When the user is done making changes in the PropertyGrid, I make the wrapper-object transfer its data to the original object.
It works, but I want to leave out this last step. I want the wrapper-object to update the data in the original object at the same time as when a property in the wrapper-class is changed. This causes a problem when the properties are nested, like mine are. When the properties of an object that is accessed by a property in the wrapper-class is changed, how will the wrapper-object know? I found an attribute that may do the trick: NotifyParentPropertyAttribute. This is a flag saying you want the parent property to be notified by a changed child property. However, I haven't a clue how (or if) the property should send this notification and how the parent should receive it.
So my question is: what should I do to be able to handle this notification. Has anyone come across this attribute before?
Thanks.
|
|
|
|
|
There's a couple more robust ways of doing this: implement ICustomTypeConverter on the "design-time unfriendly" object, or implement a designer. Both allow you to return a PropertyDescriptorCollection that contains PropertyDescriptor s. A designer can also allow you to pre- and post-filter properties on an object. Through custom PropertyDescriptor implementations, you can configure the categories, descriptions, read-only'ness, etc. for a property, as well as call it anything you want (and implement GetValue and SetValue however you want).
I use this for a preference manager with a temporary PropertyGrid to edit the singleton data (through the internal static instance field that returns the singleton). I implement ICustomTypeDescriptor and - for the most part - just use the TypeDescriptor methods related to whatever method I'm implementing for the ICustomTypeDescriptor . For GetProperties , I use a custom PropertyDescriptor class that actually encapsulates rows in a database (via a DataSet that is filled/updated based on conditions) and displays them as properties on an object (with full support via the Type for TypeConverter s, UITypeEditor s, etc.).
This way, the user is actually changing the object without you having to shadow properties like you are now.
The NotifyParentPropertyAttribute simple causes the designer to use the information it has (such as what's returned for TypeConverter.GetCreateInstanceSupported ) to re-create an object based on the new values in the property attributed with the NotifyParentPropertyAttribute . Very little else is documented about it, and since the implementation is primarily in the designer (i.e., the VS.NET IDE or #develop IDE, etc.) using the IL disassembler (or any disassembler/decompiler) won't be very helpful.
I recommend using ICustomTypeDescriptor or a designer.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks. I will look into it right away!
|
|
|
|
|
Hello,
I'm running the following program and getting memory leaks. The source of the leak is the "response = (HttpWebResponse)request.GetResponse();" line. When i close the connection to the response, it still won't clear up all the memory. I'm not sure why this is happening. I tried this code on an WinXP box with VS .NET 2002 and a Win 2003 Server box running Visual C# 2005 Express. I get leaks on both. I also tried calling GC.Collect() and GC.WaitForPendingFinalizers(), but that didn't help. Please let me know what i'm doing wrong here.
Thanx for the help, Amir
using System;
using System.Collections;
using System.Net;
using System.IO;
namespace GarbageCollectorTester
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
public static string GetHTML(string url_)
{
HttpWebResponse response = null;
HttpWebRequest request= null;
try
{
Console.WriteLine("B: " + GC.GetTotalMemory(false));
request = (HttpWebRequest)(WebRequest.Create(url_));
response = (HttpWebResponse)request.GetResponse();
//Console.WriteLine("A: " + GC.GetTotalMemory(false));
}
catch(Exception e)
{
Console.WriteLine(e);
}
finally
{
if(response != null)
{
response.Close();
((IDisposable)response).Dispose();
}
request = null;
response = null;
//Console.WriteLine("A: " + GC.GetTotalMemory(false));
}
return "";
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
while(true)
{
GetHTML("http://www.hotornot.com");
}
}
}
}
|
|
|
|
|
First of all, a much better way to make sure your response and requests (or anything that implements IDisposable ) gets disposed in C# (even in case of exceptions) is the using block:
HttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.codeproject.com");
using (request)
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (response)
{
}
} Also, realize that type implementations in .NET are compiled to Intermediate Language (IL). This IL is just-in-time compiled (JIT compiled, or sometimes just "JIT'd") into native code which is cached in memory, as well as any type member implementations used by that type. There will be some increase that will not "go away" because it is the native code that is being cached.
If the memory continues to increase (after disposing both objects and any other objects you use that implement IDisposable ) after several calls to your GetHTML method, try calling GC.Collect to see if that cleans up memory (remember there will be some overhead for the cached native code). If so, then there's probably something else you can dispose.
The main thing to remember is to always dispose disposable objects and let the GC do it's job. This may not always produce the best effect on your target machine, but remember that the .NET Framework - like other larger frameworks like Java - require many more resources than native applications typically do.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thanx for your reply. I'm aware of using the "using" statement. The code I posted does what "using" does. It is just more verbose. I also tried using GC.Collect() before and d it didn't do much to help. I think the GC.Collect() is just a hack. you should not have to use it.
I actually ran the code in visual c# express again. it seems to handle it ok. I guess i didn't run it long enough before. Looks like a .NET Framework 1.0 bug with the HttpWebResponse component not collecting properly.
thanx,
amir
|
|
|
|
|
Thank you - I'm very much aware you should run GC.Collect which is why I mentioned you should try it - "try" being the optimal keyword here. The idea was to see if any data was not being released immediately, or if it was just the cached native code after the JIT compilation.
Yes, using equates to a try-finally but you weren't doing this for the HttpWebRequest . using is just short-hand and was only a suggestion to you to make sure that everything - including request objects - were disposed even if an exception was thrown.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how can i do something like
If (DateTime.Now >= StoredDateTime) ???
i extract the StoredDateTime from database which is save in earlier time useing
DateTime.Now.ToString();
I don't know the setting of time in the machine so i can't expect the returned format .... so how can i accomplish this task..
ADEL K Khalil
|
|
|
|
|
Why are you converting the DateTime to a string. Why not keep it as instance of a DateTime object, you can then use the compare method.
Also, use DateTime.UtcNow, instead of Now - this will ensure that your time is always stored using the same timezone. It's should be quite easy to convert it back to the user's timezone for display purposes.
If your stuck saving it as a string to the database, then you should be able to use the string format objects to control the format it is saved as.
|
|
|
|
|
Chris is right, try to make the structure in your database hold a DateTime object and not a string. If you try to query the database for dates using comparisons other than equals, you'll get unexpected results since it'll be returning rows based on the STRING value of the datetime, not the actual datetime.
Good luck!
|
|
|
|
|
How can you read the Row Height in a DotNet Datagrid?
AeroBatty
|
|
|
|
|
Since all of the cells in a given row will have the same height, you could use the GetCellBounds( rowNum, colNum ).Height to get the height of any row you want. For instance:
dataGrid1.GetCellBounds( 1, 0 ).Height;
would retrieve the height of row 1.
Hopefully that helps you out!
Good luck!
- D
|
|
|
|
|
Hi,
We are in need of some c# tutorials to be written for us. The writers will be reimbursed for the work.
These materials should not be copied from elsewhere. This might be a good opportunity for people who have worked on c# projects for more than a year and want to share their expertise.
If these materials are good enough, this can become a good long term opportunity for these experts.
If interested, please write an email with your interest and expertise level to checker_src@lycos.com or reply to this thread.
Thanks
Muthu
|
|
|
|
|
I want to know some detail about your tutorial, such as what kind of material you need or what is that for, how to organize your tutorial.
Alan Shen
|
|
|
|
|
Can you write an email to my id? My id is checker_src@lycos.com
Thanks for your interest.
|
|
|
|
|
I *might* be interested, but not without knowing what types of tutorials you're looking for, what topics you're interested in, and what it's going to be used for.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
SELECT * FROM user WHERE clue IS NOT NULL
GO
(0 row(s) affected)
|
|
|
|
|
Well we can start with the basic level tutorial. The following is
a rough TOC. If you are interested please send an email to checker_src@lycos.com. It will take 6-12 hrs for me to reply because I might not be having access to external email during office hours. We can discuss the payment and deliverables in emails.
The rates can be discussed. If things are acceptable, it can be a long term opportunity for who can provide original and good content.
TOC:
Each topic should include enough code sample/snippet whichever is applicable. Tutorials should start with compiling the program from command line using csc.exe, then progress to using visual studio.net.
1. Basics of .NET
2. C# basics - compiling code
3. C# data types
4. OOP & C#
5. Intermediate Languate
6. C# Namespaces, classes methods, properties in c#
7. exceptions
8. delegates & events
9. overloading operators
10. Windows Forms - Usage & samples for all controls
11. Controls (I expect the number to be approximately 10-15) Button,
Checkbox, listbox, combobox, menu, grid, Label, Edit control, radio
button, progressbar, tab control, filedialogs, color dialog, tree control,
tool tips.
Also:
ADO.NET - Samples
Printing - samples
After finishing the above, pls do consider the following
intermediate/advanced level topics.
1. Reflection in C#
2. COM Interop
3. Inheritance
4. interfaces
5. Attributes
6. Web services intro
7. Sockets in C# - Server & client
8. Multi-threading in c#
|
|
|
|