|
Add to that this doesn't exist there
But hey it happens to me as well (have a look at my reply to text searching in a stream, for example, lol)
|
|
|
|
|
Thank you for the reply.
The article C# and beforefieldinit[^], under the section "The curious nature of beforefieldinit - lazy or not?", indicates that the static constructor will still be lazy.
I'm looking for a way to force these static objects to be created when the assembly is loaded.
Any ideas?
Thanks!
|
|
|
|
|
This is a hack, but, you could declare some static function in it that doesn't actually do anything, and call it when your program starts. Then the static ctor will have to be invoked, or at least that is my understanding.
As for doing it as soon as the assembly is loaded.. I have no clue - does it really have to be at that precise moment? Calling the "do nothing" function form the static constructor of the class that contains Main might be the closest you can get to that, in an executable (for a DLL I have even less of a clue)
|
|
|
|
|
Aha! Spotted this:
Anticast wrote: _items.add(this);
note the italics. You can't add an item until it has, at the very least, been instantiated as the presence of the this keyword indicates. Even a Dummy Run method would have to instantiate an instance for it to be added, even if the method was itself static.
You could instantiate explictly the subclasses (possibly via reflection, getting all subclasses of MyClass ). But this too is long winded.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
The this is used inside the class constructor, not the static constructor, so there is an instance to add to the list.
Here is a striped down layout of how I'm trying to do it.
public class GlobalList
{
public static List<GlobalList> listItems = new List<GlobalList>();
private string _someImportantData;
public GlobalList(string data)
{
_someImportantData = data;
listItems.Add(this);
}
}
public abstract class PlugInBase
{
public static void Initalize() { }
}
public class MyClass : PlugInBase
{
public static GlobalList MyClassGlobalList = new GlobalList("MyClass data");
public MyClass()
{
}
}
static class ExeClass
{
static void Main()
{
MyClass.Initalize();
GlobalList.listItems.Exists(...)
}
}
I want my program to search all .dlls in a "plug-in" folder, then search those dlls for any class of type "PlugInBase", and those classes will be "initalized" so the static items can be created. But I'm not currently able to get the "MyClassGlobalList" to be created. I can't refrence it directly since my program won't know how the class derived from "PlugInBase" will create its "GlobalList" item. I'm also not able to mark Initalize in PlugInBase as abstract, so I can't deligate the creation to the child class.
Any ideas, or maybe a different approach? I'm open for anything that works at this point.
Thanks!
|
|
|
|
|
Sorry, this approach won't work - you can force the creation of the list, but you can not force the classes to magically instantiate themselves (but you could use reflection to do that). In any case, you can't avoid reflection completely in a plug-in system.
I'm sure there is at least one article on CP that deals with it, though.
Edit: typically they would use reflection to get all classes that implement an plug-in interface or derive from some class, and then instantiate instances of those classes.
|
|
|
|
|
Thanks, this is the method I will be using now.
|
|
|
|
|
Hello,
I made my app for a fixed dimension, and when a person changes the Font Size (Display Scheme) from windows to Large (125% size or 150% size ...) all the text from my app is not visible anymor (because the text is to large) and also, the picture boxes are larger than the images (making the image tile over the picturebox).
How can I make it so even if the Display Scheme is 150% size, my app will be visible like it is 100% size (normal size) ?
I really hope someone can help. I searched all over the place but I didn't manage o find anything useful ...
Thanks
|
|
|
|
|
Try the Form.AutoScaleMode property. Setting it to None should solve your problem.
|
|
|
|
|
Hello,
I already tried this but with no luck. I know I have to use it before the InitizializeComponent call and it's simply not working.
I am making tests with Larger FOnt size in Windows 7, and both text and controls are larger. I want them to stay the same like on normal Font size scheme .
Any other suggestions?
Thanks
|
|
|
|
|
Hi! Is there any way to force ClearType text rendering (regardless of the current windows settings) for a System.Windows.Forms.TextBox control?
Custom drawing of a textbox (OnPaint, Message Handling etc.) doesn't work.
Thanks in advance!
|
|
|
|
|
the post it's rather old but i'll write an answer anyway for others to see it .. so here it is:
by overriding the OnPaint method should work just fine,
subclass the textbox class and in the constructor add the UserPaint style like this:
this.SetStyle(ControlStyles.UserPaint, true);
after that, override the OnPaint method and add the following line:
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
now you may use e.Graphics.DrawString(this.Text, ...) to paint the text.
NO. Layers. Onions have layers. Ogres have layers. Onions have layers. You get it? We both have layers.
|
|
|
|
|
Dear coders,
I have a powerpoint file with narrations(also called audio recording). I would like to convert the ppt file into a .avi and .3gp format. Am comfortable with C#. I can also learn C++ . I have seen already existing systems that do it all, however their code is not available.
How can I move on with developing this application?
It will be helpful to get links to opensource solutions, or tutorials on how one can write an application that does the job.
Regards,
Simon.
|
|
|
|
|
Do you want to really write the application to do this?
CamStudio does a fantastic job to do exactly this.
|
|
|
|
|
|
Hi all. I have an Excel spreadsheet that looks like:
Xls Pictures
I'd like to convert this to some XML that looks like:
<UserName>
bla1
</UserName>
<Mail>
bla1[at]bla2.com
</Mail>
<Address>
World
</Address>
can anyone help me do this in C#?
|
|
|
|
|
It depends on the version of Excel you are using. From Excel you could save save the spreadsheet as XML, or from code you could use the Excel interop to do it, then use XSLT to transform it into the desired output. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Well, be more specific.
Which version of excel are you using? Is what you are doing a one-time deal, or do you need to do this repeatedly?Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
|
As you are using Excel 2003, and if you are doing this once, you can just save the spreadsheet as XML.
Otherwise you'll need to interop with excel to read the spreadhseet data, see http://support.microsoft.com/kb/302084[^] for more advice on how ti start this. You'll also find "Linq Xml" a usful term to google, for when you need to write te data out.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
|
Hi ...first problem in C#
Basically I have a Base class and multiple derivs from Base.
All derivs are part of a Tree, so the mytree has somthing like CNode<CBase>
Now my question is is any way to make (force), override ToString() in my derivs class.
I will keep my all derivs class derived from Base.
so I can't use another abstract class and derive from this also.
I guess the only way is true by another interface, but how do I do this?
(if I put a simple interface and having func replaced with another func..mToString() -> this will be virtual in my Base and make derivs:INewInterface {string mToString()} doesn't work either because the compiller will consider having definition from Base )
thx
interface IBase
{
string ToString();
}
class CBase
{
public override string ToString()
{
return "Base";
}
}
class CDeriv1 : CBase, IBase
{
public override string ToString()
{
return "Deriv1";
}
}
class Program
{
static void Main(string[] args)
{
CBase nod = new Deriv1();
}
}
|
|
|
|
|
To do this (which isn't wise) need to create an abstract class:
abstract class CBase
{
public override abstract string ToString();
}
class CDeriv1 : CBase
{
public override string ToString()
{
return "Deriv1";
}
}
class Program
{
static void Main(string[] args)
{
CBase nod = new Deriv1();
}
}
But I think doing this to ToString() is a bad idea, you should either call your method something else, or just override the existing ToString() method.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
You can mark the ToString method as abstract, however, a better design would be to mark it as virtual. I know the language. I've read a book. - _Madmatt
|
|
|
|