|
In VB you are able to import a class instead of just a namespace. is there any way to do this in C#? I tried to import a class and it won't let me.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
now why in the world would you want to "import" a class instead of a namespace?? That would make all of the fields of the "imported" class fields of the "importing" class. ...What you are describing is inheritance. Look here http://msdn.microsoft.com/library/en-us/vbls7/html/vbSpecStart.asp
Allowing what you are requesting would break object oriented design
(Nyquist Rate || ! Nyquist Rate)
{
Console.WriteLine("That is the question");
}
|
|
|
|
|
You can apply 'using' to a class if you use an alias:
e.g.,
using filealias = System.IO.File;
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter, VB to C++ converter
Instant Python: C# to Python converter, VB to Python converter
|
|
|
|
|
using is only for namespaces, not to bring a class into scope, or is it ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Yes. You can do:
using System.Windows.Forms;
using Timer=System.Threading.Timer;
namespace xx {
class yy {
Timer timer=new Timer();
}
}
Luc Pattyn
|
|
|
|
|
Oh, I knew that. He wants to do this
using System.IO.Path;
class x
{
void somemethd(path)
{
string ext = GetExtension(path);
}
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
yeah basically i have a namespace called UVNET and i have a class called UniArray in that class has a bunch of static methods (one being called Extract) what Extract does is returns a string. Instead of doing
string myName = UniArray.Extract(someString, 2);
i would like to do
string myName = Extract(someString, 2);
a co-worker works with VB and said that instead of Importing just the namespace (i.e Imports UVNET) he can actually import the class also (i.e. Imports UVNET.UniArray) so he can just use the functions without calling the class over and over again. I was just wondering if there was a way that it was possible with C#. I mean its no big deal really it would just make the code look cleaner if i didn't have "UniArray" all over the place. This class has about 25 funcions that i use regularly and to me it would be easier if i could just type in the method itself
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Here[^] is a link to a screen capture i took while doing it in VB so you could see what's actually going on.
-- modified at 21:20 Monday 29th January, 2007
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
VB really sucks, and has a lot of hangover stuff from VB6. You're seeing some syntactic sugar here, that I don't think is supported in C#, and I'm kind of glad. the .NET framework is fully OO, creating these sort of globals is not really in keeping with how it should all work.
The equivelant statement is 'using', so if it works at all, then using MyNamespace.MyClass; is how it would work.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thanks Christian for helping me get to the bottom of this. I had a feeling about this not possible i was just hoping i was overlooking something. Thanks again!
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Good day everybody
There are cases on a form when the user might create a new row for example and not complete all the mandatory information as imposed by the database. In other words if you forget to enter data in a textbox binded to a datacolumn that does not allow nulls.
In that case if the user leaves the row somehow a NoNullAllowedException will be thrown. My problem is I am not sure what is the best way to handle this.
I thaught i could c,apture an event on the BindinSource but there is no "PositionChanging" event there is just a PositionChanged event, which of course is too late.
I could also take care of the case in the form itself but it seems like a lot of code for something that could be so simple.
Any suggestions?
Very confused
|
|
|
|
|
If you were using a DataGridView you'd be able to use the DataError event (I think that's the name) to capture it. You may have to handle it manually on a 'Save' )by checking a value isn't null before committing to the DataSet / DB) if you're using your own custom GUI for editing rows.
|
|
|
|
|
Hi @all!
I've got an amazing problem... or better a driving me crazy problem...
i have this code in print event...
StringFormat strFormat = new StringFormat();
strFormat.Trimming = StringTrimming.None;
strFormat.FormatFlags = StringFormatFlags.NoClip;
RectangleF InfoRect = new RectangleF(curXPos, nCounter, (e.MarginBounds.Right - CurXPos), newFont.Height);
e.Graphics.DrawString("Hello World! Test Text", newFont, brush, InfoRect, strFormat);
as anyone can see: newFont is a Font var, brush a brush, InfoRect a RectangleF and strFormat the StringFormat...
Ok, the problem now is quite simple... or for me not:
if the Text doesn't fit to InfoRect it's wrapped to next line... my problem is, how do i calculate the height of the needed space - especially the height - if it's not wrapped it's no problem, but when it's wrapped, i don't know how to get the height - i need the height to be calculated before the text is drawn by DrawString !!! i draw a rectangle around my text... so i need to know the height before... any suggestions??? Thank you!!! All ideas are welcome...
Ralf
FreewareFire is in the House!
|
|
|
|
|
There is Graphics.MeasureString()
You should use it with the same arg list as Graphics.DrawString()
except that the bounding rect must be replaced by the rect's size
(since measurestring does not care about the location)
and it will return the rect size DrawString() would like to have.
Both know how to do word wrapping.
Normal usage would be: give it a rect with the available width and a very large height,
it will calculate the effective width and the required height; if you have sufficient
height available, then do DrawString with the original height and width and the text will fit.
If you have insufficient height, and call drawstring anyway only part of the text would be drawn.
Luc Pattyn
|
|
|
|
|
Well, it works! Damn, i've forget the strFormat at MeasureString-Line... *lol* - now it works fine! Many thanks to you Luc! - you gave me the solution!
Thanx a lot!
FreewareFire is in the House!
|
|
|
|
|
Hi Everyone
I'm doing a program where I want to play an audio file. In the mean while I want to do some audio processing in the background which in my case is quite CPU demanding. My concern is that I want be able to play music simultaneously and have to wait for the processing... so I was thinking if someone has some suggestions on how this can be done ...
Thanks in advance
Al
|
|
|
|
|
Hi,
have your calculations handled by a background thread running at a lower priority
(Priority.BelowNormal).
Luc Pattyn
|
|
|
|
|
Hi,
I created a small Windows app that displays variables values with Console.Writeline. It compiles correctly, but it displays a screen in less than half a second then I can't see the output. Why is this?
Regards,
ma se
|
|
|
|
|
You should prevent your app from terminating (and closing its console); typically this
is achieved by adding these two lines at the end of your main method:
Console.WriteLine("Hit enter key to terminate...");
Console.ReadLine();
Luc Pattyn
|
|
|
|
|
|
hello
I want to find this assembly file
how can I find it?
have anybody this file?
it is in microsoft embeded windowa
microsoft.pointofservice.dll
please help me to find
if u know, please tell me
my email is hamed_r81@yahoo.com
Masterhame
|
|
|
|
|
|
Hello,
I have a question regarding the crystal report. I have a program that will print custom bills and I use for that crystal report, the user can not view the report its only called to be printed.
The database connection used has a local path on my computer. How can I make it dynamic so I can use it on other computers as well?
Thanks.
Regards,
Butterfly
|
|
|
|
|
I simply created a Windows Control Library project in VS. I add 2 user control form. On one form there is only a button and the sencond user control form i add a text box. So let say i want to import only one of them in my another project how do i do this. I don't want to import or add reference for both user control.
Secondly when i looked at my usercontrol project debug directory it created a project dll. I want dll for specific one.
thanks
|
|
|
|
|
If the controls are in the same project you have no choice, you will get both as you are referencing the assembly, not the controls.
only two letters away from being an asset
|
|
|
|