|
"second that" is fine too
|
|
|
|
|
Hard to know for sure, but I'd guess that the problem is that you've got a form showing modelessly ( show instead of showdialog ) and it doesn't show while the thread is busy with other processing you do directly after. Call ShowDialog and your code will stop until the form is closed. Use a seperate thread to do processing and keep your UI working, or call Application.DoEvents to force a paint event.
Hard to say if this is the problem, without seeing the code.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Do all your work in the OnShown method of your main form (which happens after the form is, well, shown). The next step would be to take Luc's advice and port your initialization code to a separate thread which could be called from the construtor or the OnLoad event.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
OnShown is the perfect answer. Now the user can see all the messages as the program runs. Thank you so much.
|
|
|
|
|
Why is it that this class is listed as part of .Net 2.0, but I cannot locate it? I am using the .Net framework version 2.0.50727. Does anyone know why this class is unavailable to me? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
modified on Wednesday, December 12, 2007 12:47:42 PM
|
|
|
|
|
|
Wow, that is weird... I was already using things like RijndaelManaged class from the System.Security.Cryptography namespace without adding the reference to System.Security. However, to use the ProtectedData class I needed to have that reference. Why the inconsistency?
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
You set a reference to a project, .DLL, or some other library.
You import namespaces, not set a reference to them.
Yes, you already set a reference to the System.Security.DLL. Then you imported the System.Security.Cryptography names contained in the DLL. Importing System.Security.Cryptography does NOT automatically import its parent namespaces, System and System.Security. There is no inconsistancy.
|
|
|
|
|
Actually, the flow went like this...
using System.Security.Cryptography;
namespace foo {
public class myClass {
private RSACryptoServiceProvider m_AsymAlg =
new RSACryptoServiceProvider(ASYM_KEY_SIZE);
private RijndaelManaged m_SymAlg = new RijndaelManaged();
}
}
Then, I tried to access the ProtectedData class from the SAME NAMESPACE I had previously imported, but that reference was NOT there. Why was I able to access both the RijndaelManaged and RSACryptoServiceProvider classes without the reference to System.Security(.dll), but not the ProtectedData class? This seems like it is inconsistent, unless the two are in different DLL's with the same namespace declared. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: unless the two are in different DLL's with the same namespace declared
Bingo! Yes, multiple DLL's can contribute classes to the same namespace.
If you look at the documentation in MSDN for the Rijndael and RSACryptoServiceProvider classes and you see, at the top of the "about" page for every class, which namespace and .DLL the class resides in. These two classes sit in the .NET Core Library, which is "mscorlib.dll".
There are examples of this "multiple contributors" scheme all over the .NET Framework.
|
|
|
|
|
Please try as Dave said.
SSK.
Anyone who says sunshine brings happiness has never danced in the rain.
|
|
|
|
|
Hi all!
I can't make an image is printed in the middle of a page.
I use this code:
printDocument = new PrintDocument();
printDocument.OriginAtMargins = true;
printDocument.DefaultPageSettings.Margins = new margins((int)printDocument.DefaultPageSettings.HardMarginX,
(int)printDocument.DefaultPageSettings.HardMarginX, (int)printDocument.DefaultPageSettings.HardMarginY,
(int)printDocument.DefaultPageSettings.HardMarginY);
x = xCenter;
y = yCenter;
x -= MeasureConverter.FromUnitToUnit(UnitOfMeasurement.Inches, UnitOfMeasurement.Millimeters,
printDocument.DefaultPageSettings.HardMarginX / 100);
y -= MeasureConverter.FromUnitToUnit(UnitOfMeasurement.Inches, UnitOfMeasurement.Millimeters,
printDocument.DefaultPageSettings.HardMarginY / 100);
...
X and Y are given in millimeters, and in my printDocument_PrintPage method I have:
Graphics g = e.Graphics;
g.PageUnit = GraphicsUnit.Millimeter;
g.DrawImage(printableObj.GetMetafileImage(), x, y);
g.Dispose();
e.HasMorePages = false;
Unfortunately my image is printed not exactly in the center...
Can you help me, pls?
Thnks in advantage.
|
|
|
|
|
Do you have this working yet?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I still have this problem...
|
|
|
|
|
I am not sure if I am not understanding the use of interfaces or just going about this the wrong way. Any help would be appreciated. Here is the gist of what I am trying to do:
I have a class - Dog - which implements a few basic methods such as tail-wagging and slipper chewing:
class Dog {<br />
void wagTail(){...};<br />
void chewSlippers(){...};<br />
}
Now I wish to create a bunch of types of dogs, so:
class doberman : Dog {...)<br />
class labrador : Dog {...}<br />
class chihuaha : Dog {...}<br />
etc.
So far so good. Dobermans, labs and chihuahas can all wag their tails and chew slippers. But I also want dogs to be able to do a trick, so I thought I would force the programmer to create the doTrick method by making it an interface:
interface IDog {<br />
void doTrick();<br />
}
Here is my problem. The programmer is going to deal with the instances of dogs as part of a collection, so he is not necessarily going to know if the object being used is a doberman or a labrador or what. e.g. the code may look like:
foreach ( Dog myDog in AllDogsInMyHouse ) {...};
If I implement the interface on the individual classes
class doberman : Dog, IDog {...)<br />
class labrador : Dog, IDog {...}<br />
class chihuaha : Dog, IDog {...}<br />
etc.
the programmer must create the doTrick() method for each one - great. But the programmer isn't able to call myDog.doTrick() because doTrick is not defined for the class myDog.
If, instead, I implement the interface on the class myDog
class Dog : IDog {<br />
void wagTail(){...};<br />
void chewSlippers(){...};<br />
void doTrick(){...};<br />
}
the programmer can call myDog.doTrick(), but I now have to provide a default method for doTrick() which is automatically inherited by doberman, labrador, etc. This defeats the purpose - the programmer is not forced to create a doTrick() himself.
Is there a way for me to accomplish both goals?
Clive Pottinger
Victoria, BC
|
|
|
|
|
Make the class Dog abstract, so you will have the following:
abstract class Dog : IDog {
void wagTail() { ... }
void chewSlippers() { ... }
abstract void doTrick();
} Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Many thanks. That worked.
I had read about abstract, but it didn't quite make sense to me until now.
Clive Pottinger
Victoria, BC
|
|
|
|
|
What Jeff said is the right way to do it; the Dog class should be abstract, and there should be an abstract method called DoTrick on it.
Another way of doing this, if you wanted to keep the Dog class non-abstract, you could do it like this:
class Dog
{
public virtual void DoTrick()
{
}
} Notice the virtual method - that means derived classes, such as Dobermans, can override that method and provide their own implementation:
public class Doberman
{
public override void DoTrick()
{
...
}
} This will accomplish the same thing: all dogs can do a trick. However, it doesn't force derivatives to implement DoTrick; if Doberman didn't override it, DoTrick would exist but would do nothing (e.g. see the Dog.DoTrick method). If you want to force derivatives to provide a custom DoTrick method, an abstract method is the way to go, just like Jeff showed you.
|
|
|
|
|
While the above answers are correct, I'm going to throw a one into the pot that you might not be aware of. You can use Partial Methods to accomplish a similar thing in .NET 3.5. Basically it allows you to put a call to a partial method and call it from your code. If the method is present, in the implementation then it will be called otherwise it will be compiled out. Take a look at this[^] site for more information.
|
|
|
|
|
I'm drawing a Splash Screen (Custom Shaped WinForm) as follows
class SplashScreen : Form
{
Image splashImage;
public SplashScreen()
{
this.TopMost = true;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = this.TransparencyKey = Color.White;
this.BackgroundImage = splashImage = Bitmap.FromFile(SplashFileName);
this.Size = this.BackgroundImage.Size;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(this.splashImage, 0, 0, this.Width, this.Height);
}
}
and showing it in my Main method as
class MainForm : Form
{
public static void Main(String[] args)
{
SplashScreen splash = new SplashScreen();
splash.Show();
MainForm mainForm = new MainForm();
mainForm.Shown += delegate(object o, EventArgs ev)
{
splash.Hide();
splash.Dispose();
mainForm.Activate();
mainForm.Focus();
};
mainForm.Show();
Application.Run(mainForm);
}
}
Now the Issue is that the Splash Screen shows fine as per the Image from "SplashFileName" but just before showing it shows a Black Rectangle for some milliseconds. What I expect is that the Splash Screen be shown while my program is loading stuff and hide as soon as the MainForm gets Shown. So Where am I missing?
Please Advice
Thanks...
|
|
|
|
|
Hi,
as the splash image seems intended to fill the splash form, I see no reason to call base.OnPaint()
so I suggest you take it out.
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint(e);<br />
e.Graphics.DrawImage(this.splashImage, 0, 0, this.Width, this.Height);<br />
}<br />
I tried removing base.OnPaint(e) from above and removed the above method completly but still a get a Black Rectangle of the same Dimensions as my Splash Screen before I the latter becomes visible
|
|
|
|
|
Hi,
I did some experiments, and it clearly is this.TransparencyKey = Color.White;
that causes the initially black window. If you remove it, everything looks fine; if you need
transparency, there might not be a solution (except maybe switching to WPF).
|
|
|
|
|
Thanks for the reply. Yes taking out this.TransparencyKey = Color.White; does get rid of the Black Rectangle but my Image is not Rectangular. I know that we can draw Non-Rectangular WinForms using
this.BackColor = this.TransparencyKey = SomeColor; //Color.White in my case
In case you want to investigate further then my SplashForm Image is located at
SplashScreen Image[^]
|
|
|
|
|
Ok, I have a set of graphics paths that are drawn to a Panel on a Form. This Panel will at times expand and require scrolling to see more of the area. However, when redrawing the Graphics paths or using hit detection, the Graphics paths don't seem to be operate within the panel's client area, rather, operating on the panel as if there were no scrolling.
What suggestions would you recommend to alleviate this problem?
|
|
|
|