|
Quote: Shape s = new Rectangle();
The short answer is:
You created a "rectangle"; but you are telling the system / compiler to treat it as a "shape"; hence no "num".
If you want to access the "same" rectangle as a "Rectangle" AND as a "Shape", you can do this:
Rectangle rect = new Rectangle();
Shape rectShape = rect as Shape;
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: Shape rectShape = rect as Shape;
No need for the as Shape there, since Regtangle inherits from Shape .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am trying to access the default font of the printer. can anyone help me on this?
|
|
|
|
|
There is no such thing as far as the driver is concerned and a lot of printers don't even have one. Even if you did get it, chances are good that there is no matching font on the machine, such as "Default".
What's the point of this anyway?
|
|
|
|
|
Printers don't have default fonts - you're thinking of a Typewriter and that has one font only. Printers don't actually print text - they receive information that describes what to print, and where, and the closest analogy to this is that they receive images, which may just happen to represent text.
This space for rent
|
|
|
|
|
Which is why print files are so damn huge...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In the bad ol' days printers certainly did have default, and other, fonts, in replaceable cartridges. You young people just don't know you're born.
|
|
|
|
|
I remember when you had to change the chain to change the font!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
What kind of printer is it? A dot-matrix? If that's the case, then you can force it to print the default font if you add it to Windows as a "Generic Text" printer, instead of using the higher level driver.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
You have a solution in mind that is unlikely to work and you are trying to figure out how to make it work.
Instead you should define what the problem is and then ask about possible solutions. And provide sufficient detail about the problem.
As noted by the other replies there are many possible solutions because there are many possible problems.
|
|
|
|
|
by using the default drawing method i tried to print through usb and it is printing also
example:
Font f1;
f1 = new Font("Calibri", 14, FontStyle.Regular, GraphicsUnit.World);
e.Graphics.DrawString(pLine, f1, Brushes.Black, new Point(-90, 30));
now here i am able to print in all the fonts which is available in msword
but when i am printing through serial port(com port) the font is totally different
now i want to print in the same font which it is using when i am printing through serial port.how do i get that font that's my question
printer used : essae thermal reciept printer
when i am doing selftest of printer it is printing
default ASCII Font : FONTA
Default code page : page0
now i hope so my question is clear...
|
|
|
|
|
There is no way to determine that and it will not help you as there is likely no equivalent font in Windows.
What do you think knowing which font the printer is using is going to do for you?
|
|
|
|
|
In Microsoft Visual Studio Enterprise 2015 I have created the simplest Windows Forms Application (.NET Framework 4.5.2.):
On the main Form1 there's a button1. When you press it the Form2 opens and closes immediately and loops with this Form2 open and closure.
On Windows 10 Task Manager you will see the memory usage increasing . I expect the memory to be released instead . Obviously after some time the memory usage will be huge and cause problems.
It's a test that anyone can do. How can this be possible? Even if I decrease the loop and wait for the cycle to finish, the memory is not released.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int loop = 100000;
for (int i = 0; i < loop; i++)
{
using (Form2 a = new Form2())
{
a.ShowDialog(this);
}
}
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Close();
}
}
Mr. Burns
Montgomery Burns
|
|
|
|
|
No, the memory is not released automatically - the heap will be freed and recycled when the Garbage Collector runs and detects the unreferenced items. This may not happen for some time, but even when it does occur, the amount of memory shown in the Task manager will probably not decrease: the framework doesn't release memory back to the OS automatically when it compacts the heap.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
When run for a long time, the application will make the whole system stuck. How would you solve this?
|
|
|
|
|
No, it won't - at some point the GC will run and compact the heap, releasing the memory for other uses within the app. But the framework doesn;t release the allocated memory back to Windows unless Windows starts to run low on resources - at which point the GC happily deallocates it back to the OS. The value in the Task Manager just indicates how much the framework has grabbed so far, which is not the same as the amount of memory your app is using at all!
To accurately investigate your app memory usage, you would need to use a profiler, such as dotMemory[^] or Redgate ANTS[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Quote: No, it won't It will and it's been verified. I have checked it also with Redgate ANTS profiler, the memory is never freed. The operating system interface slows down and sometimes OutOfMemoryException appears.
|
|
|
|
|
Ahem,
Quote: Because a form displayed as a dialog box is hidden instead of closed, you must call the Dispose method of the form when the form is no longer needed by your application.
|
|
|
|
|
He creates it in a using block, so Dispose should be called automatically.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've been looking at code way too long. I completely missed the using and just expected to see the Dispose somewhere after the ShowDialog().
|
|
|
|
|
I know the feeling - I keep reading what I meant to write...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Read the documentation on ShowDialog[^]. If you show a form using ShowDialog, you are responsible for Disposing the form when you're done with. Failure to do so will result in memory and resource leaks.
|
|
|
|
|
Is this true even if you call Close() in the AcceptButton and the CancelButton handlers?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|