|
Why don't you just extend WebControl instead of Control ? This is the correct way to make your own WebControl so that you inherit all the functionality from WebControl , which you obviously seem to want.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I initially desired to do so but you know Heath, Webcontrol has 'forecolor', 'bordercolor', ... and other properties that I don't need in my Wencontrol at all. I guess Microsoft should have not include all these properties that are not really generic in all webcontrols or I can say better they could include other light weight class that only had properties available to all UI webcontrols.
anyway can you help me to implement 'Style', 'Width' & 'Height' myself?
Thanks
---
"Art happens when you least expect it."
|
|
|
|
|
If you don't need them, don't use them. Nothing says you have to. And if you don't want them to show up in the designer, override the properties and attribute them with BrowsableAttribute(false) and EditorBrowsableAttribute(EditorBrowsableState.Never) , which is very common in many classes throughout the entire .NET FCL.
If you want to do it the hard way, the Width and Height are simple properties that store the width and height either in private fields your class can use or - more commonly - in the ViewState . The Style property is a little extra work but there are classes in the respectible ASP.NET namespaces that can help you parse and resolve these. Just read the documentation for the namespaces and browse the classes.
Seriously, though, just hide the members you don't want to support from the WebControl base class. You'll save yourself a lot of work. For example:
public class MyWebControl : WebControl
{
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override Unit Width
{
get { return base.Width; }
set { base.Width = value; }
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
nt
---
"Art happens when you least expect it."
|
|
|
|
|
Hi,
I have a control I am making (inherits from Control), called ExtendedListView, in which I use two sub controls to perform drawing operations in. Problem is, in these sub controls (which are classes inheriting from Control, inside of ExtendedListView), when I call this.SetStyle(ControlStyles.DoubleBuffer, true), an exception is thrown (not on that line, but sometime after) in System.drawing.dll.
If I call DoubleBuffer in the main class (ExtendedListView), everything is ok. If I delete the DoubleBuffer code from the sub-controls then everything is ok. However, I need these sub-controls to have DoubleBuffer as I am using them to draw into.
I can't see where the exception is because it happens somewhere not in my code. Does anyone know of this error? Why is it happening?
Thanks!
Yaron
|
|
|
|
|
One easy way to get missed exceptions is to wrap the code inside of your
static void Main() function with this:
try
{
}
catch (Exception err)
{
System.Diagnostics.Trace.WriteLine(err.ToString());
}
With that, you should get a detailed report of the error information, which is always a help.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Thanks John,
Here is what comes up:
System.ArgumentException: Invalid parameter used.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Test.Form1.Main() in c:\documents and settings\yaron\my documents\visual studio projects\visual c#\extendedlistview\test\form1.cs:line 146
|
|
|
|
|
I personally don't have an answer to this one. Sorry.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Typically, a better way is to handle the AppDomain.UnhandledException or Application.ThreadException events. Putting a try-catch around your Application.Run statement only catches exception that would cause the message pump to terminate.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Right. I just thought that this was easier to explain and understand, and it would get him the error message he needed to see.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
If you look at the dcoumentation for the ControlStyles.DoubleBuffer member, you'll see that the ControlStyles.AllPaintingInWmPaint and ControlStyles.UserPaint are also required to be set to true in SetStyle . This means that you'll have to make sure to call base.OnPaint in your OnPaint override and handle the WM_ERASEBKGND message (if not already handled by the ListView ,w hich you can find out using ildasm.exe) to call OnPaint as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear All,
I want to know, is there any inconvenients / mistakes will occur if I use an ArrayList to store up some classes dynamically? The class contains quite a lot of infos.
In my application, I need to create a class array e.g: ImageInfo[] imgInf, however, I the size maybe change at anytime.
For example, inside Init function, I will create an array as :
ImageInfo[] imgInf = new ImageInfo[1];
The size of array should be at least one, and its size will increase / decrease when I add/delete infos.
I don't know, how can I dynamically insert/remove a new array to imgInf, so I decided to use ArrayList to store the class,; e.g. use ArrayList.Add();
but I'm worried about it will cause some mistakes..
Could anyone give me some idea?? Thank you
|
|
|
|
|
ArrayList is a good choice when the array will be changing size. If you used an actual array (whatever[]), you would need to write your own code to re-allocate the new block and copy the old stuff to the new array, making sure to insert and delete appropriately. Writing your own code when other code already exists to do the job is generally a mistake, since you'll create new bugs and spend time that didn't need to be spent.
In short, the only mistake you would need to worry about with ArrayList is if you put something in it that is not of the type that you want to be storing there. (Casting is required in order to use the object when you pull it out.)
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
You could also always extend CollectionBase (or make your own, which would implement IList which implements ICollection and IEnumerable ) and make strongly-typed params for the type you want. The CollectionBase (and many other collections, for that matter) use a backing ArrayList to store objects, but by having typed parameters you avoid putting objects of different Types in the list because the compiler would fail if you tried adding something else. Extending CollectionBase isn't hard (see the documentation in the .NET Framework SDK for information on which methods have to be overridden and an example) and ensures that you won't add an instance of a different Type to the list.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Currently I am doing a vector drawing program which user need to input text using true type font.
Previously in C++ I am doing the conversion by myself.
But I heard that .Net can do the conversion automatically for me, is that true?
Thanks a lot
songling
|
|
|
|
|
I'm not sure where you heard that, but it was probably in reference to XAML using the Avalon UI layer for Windows code name "Longhorn" to be shipped in 2007 (if they don't let the date slip again). It is 90% compatible with SVG and uses the same concepts.
The Font class as it is in .NET now is just a wrapper for all the font APIs in Win32. In fact, many of the classes (especially Windows Forms controls) just encapsulate native functionality (for Windows Forms controls, they encapsulate the corresponding common controls). All the drawing stuff is actually just wrapping GDI+ so all the native functionality provided by GDI+ is about all you get out of .NET. Now, if you were to use the Metafile class (derives from Image ) and use a Graphics object to draw a Font (while recording), then it at least records the strokes. I'm not sure how this is in relation to vector-based fonts, but the EMF that is produced is a vector image. You could always give it a try.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can apply an XSLT to an XML document fine in C#.
But an issue occures if the XSLT has a for-each.
For some reason the xmldom seems to ignore it. I have read posts from other people with this problem but no solution, any ideas? (Can some kind person try to reproduce this bug)
Heres the code I use for the transform:
StringWriter sw = new StringWriter();
XmlDocument srcDoc = new XmlDocument();
srcDoc.Load("test.xml");
XslTransform srcXSLT = new XslTransform();
srcXSLT.Load("test.xslt");
srcXSLT.Transform(srcDoc, null, sw);
Output.Text = sw.ToString();
XML Doc:
(Sorry, I made the greater thens less thens and vice versa by accident in this post )
>?xml-stylesheet type="text/xsl" href="sample.xsl"?<
>catalog<
>book id="bk104"<
>author<Corets, Eva>/author<
>title<Oberon's Legacy>/title<
>genre<Fantasy>/genre<
>price<5.95>/price<
>publish_date<2001-03-10>/publish_date<
>description<In post-apocalypse England, the mysterious>/description<
>/book<
>book id="bk106"<
>author<Randall, Cynthia>/author<
>title<Lover Birds>/title<
>genre<Romance>/genre<
>price<4.95>/price<
>publish_date<2000-09-02>/publish_date<
>description<When Carla meets Paul at an ornithology>/description<
>/book<
>/catalog<
XSL Doc:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr><td><b>Author</b></td><td><b>Title</b></td></tr>
<xsl:for-each select="//book">
<tr>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Here is the output I get:
<html>
<body>
<table border="1">
<tr>
<td>
<b>Author</b>
</td>
<td>
<b>Title</b>
</td>
</tr>
</table>
</body>
</html>
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Found out this is a documented bug in .NET
I had to resort to using the old COM objects..
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
If I were you, don't use the xsl:for-each , use xsl:apply-templates instead. This does work great and gives you greater control over multiple views (using the mode attribute). Besides, if you're doing this in a .NET application/library, interoping with COM just to get your XSLt to work is too expensive, IMO, because all the calls must be marshalled.
Also, don't use //book since you're already at the root of the document (not the root element) - it causes the XPath parser to prepare for deep traversal and isn't as effecient as, say, using catalog/book or /catalog/book. As an example using xsl:apply-templates , see the example:
<xsl:stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/"> <!-- Also serves as a catch-all so you don't
have stray elements being output -->
<html>
<body>
<table border="1">
<tr><td><b>Author</b></td><td><b>Title</b></td></tr>
<xsl:apply-templates select="catalog/book"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<tr>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there any way to for each through an enum ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Got it, thanks.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hiya. I'm using Visual C# - does anyone know how to declare a variable in say FrmMain - int myVar = 6; and then in a child of FrmTempTools set myVar to a value so i can read it again in my main form?
I have tried and can only get meesages such as undeclared variable in FrmTempTools.
Thanks anyone,
surgeproof.
|
|
|
|
|
Make the variable as public, or create a public getter property for the variable. Then just pass the Form instance to your FrmTempTools child.
public class FrmMain : Form
{
public int myVar = 6;
public FrmMain()
{
ChangeTheValue();
}
private void ChangeTheValue()
{
ChildOfFrmTempTools t = new ChildOfFrmTempTools(this);
Console.WriteLine(myVar);
}
}
public class ChildOfFrmTempTools
{
public ChildOfFrmTempTools(FrmMain mainInstance)
{
mainInstance.myVar = 12;
}
}
Also note you can use the ref or out keywords to pass the variable by reference, rather than the default of passing by value. For instance
public void Test()
{
int i = 6;
Modify(ref i);
Console.WriteLine(i);
}
public void Modify(ref int i)
{
i = 12;
}
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
thanks. i think i get it now!
surgeproof.
|
|
|
|
|
On trying to follow through and adapt your code, i only get this error: No overload for method 'bladeblahFormName' takes '1' arguments. Any ideas?
thanks.
|
|
|
|