|
Yeah, I did not respond to the 1cm bit, because it's never going to work, in the real world.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Well, I started working on a Mac long time ago, all monitors were 72 dpi and all programs
were real size, even Microsoft Word. It was marvelous, you could hold a printed page
against the monitor and print and screen would fit up to the millimeter.
When I switched to PCs and Windows (98, NT, XP), I insisted on keeping real size,
although monitors improved, one of them is at 135 dpi now. And I still manage in most
applications; biggest problem is with some web pages that insist on petite fonts,
ignoring system settings.
So I created a small background app (in C# of course) that upon ALT-S switches resolutions
to some 80% of reality (and back) for easier reading those difficult pages, keeping track
of desktop icon positions, and window sizes, restoring as much as possible when hitting
ALT-S a second time. The one thing it does not do is restore the size of the windows
that were minimized (I dont know how to get/set these values, I think they are well
hidden inside Windows Explorer). Any suggestion here would be welcome.
|
|
|
|
|
Hi,
and of course you must execute the line
this.Paint += new PaintEventHandler(XYZ_Paint);
once, typically this is done in the form's constructor.
|
|
|
|
|
I have a form with a panel called test_panel1. I need to display
a bitmap on that panel and I have this code that works.
<br />
<br />
private void SetBitmap(Bitmap bmap)<br />
<br />
{<br />
<br />
Graphics graph = this.test_panel1.CreateGraphics();<br />
graph.DrawImage(bmap, 0, 0); <br />
<br />
}<br />
I now need to add another panel, lets call it test_panel2
and I need to do the same thing. But I'd like to call SetBitmap
and pass it the panel to put the bitmap on
Something like:
SetBitmap(mybitmap,test_panel2) or SetBitmap(mybitmap,test_panel1)
and have the function look like
<br />
private void SetBitmap(Bitmap bmap,Panel pnl)<br />
{<br />
<br />
Graphics graph = this.pnl.CreateGraphics();<br />
graph.DrawImage(bmap, 0, 0); <br />
<br />
}<br />
But C# doesn't like it and I don't know what the proper way to do this is?
Any help is very very welcomed.
|
|
|
|
|
Try this:
private void SetBitmap(Bitmap bmap, Panel pn)
{
Graphics graph = pn.CreateGraphics();
graph.DrawImage(bmap, 0, 0);
}
|
|
|
|
|
So simple, yet it is so hard!
Mucho Gracias.
|
|
|
|
|
What you've been told will not work if your form is ever obscured by another form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
if you create an instance of a class that offers a public Dispose() method, you MUST
call that method when you're done. This also applies to Control.CreateGraphics()
and Graphics.FromImage() and the like !!!
|
|
|
|
|
This won't work properly. If the form is invalidated, the panel will be erased, unless this is called from a paint event, in which case, it should just use the existing graphics object.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You should handle the paint event of the panel, and draw the bitmap onto the panel there. CreateGraphics will not redraw the image if your form is obscured by another form, as no paint event will occur.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello
I made one app and put on form grid view . I write the informations to the gridview but when i restart app ther are gone .Question is : How to save a access databse in c# and all records!!??
Thx
nemanja
|
|
|
|
|
Hi.
Can anyone give me a general gude (or a link to some resources) on the subject of different image formats?
But let me explain more specifically: I have a control that shows a lot of text items whose size & format depend on the content itself. This means that every time the control is repainted, a lot of text rendering occurs. To go around this problem I use a very simple idea - render the text to an image an draw the image until the text changes.
The only problem with this idea is the consumption of a lot of RAM.
What can I do to reduce the amount of memory I use? GDI+ offeres only the abstract Image class (Bitmap & Metafile as its descendents) for Drawing Images on the screen.
Is there a way to reduce the colors or perhaps use some sort of compression when I save the Images in the in-memory buffer?
Thank you.
|
|
|
|
|
You really can't do anything. A bitmap in memory must be a bitmap, which means it's huge. You could keep it in memory as a jpeg in a stream, and re build the bitmap from that, I do that to cache a lot of images, but I believe it will be too slow to do this to keep an image that is being drawn on every paint event.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
what you ask can be found in the doc under "PixelFormat Enumeration".
but I am afraid you're idea is not very sound; replacing text by an image to speed
things up is not the way to go. Instead make your text drawing faster. Text drawing
normally is VERY fast, unless you're doing something wrong. If you need help on this,
just show some of your code.
|
|
|
|
|
Hi,
To reduce the memory consumption :
1- Use the jpeg format
2- Specify the compression level
3- Always dispose graphics objects, pens, images,.. and set them to null
Here some code to specify the compression level :
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for(j = 0; j < encoders.Length; ++j)
{
if(encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression )
{
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter( Encoder.Quality, lCompression );
ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
image.Save( szFileName, ici, eps );
}
|
|
|
|
|
I have a program it contains 7 dll files and 1 exe files.
but i see dll files can be used by other developer by adding referance. How could i restrict this? Or could i add files to Exe ?
|
|
|
|
|
Hi,
if all your source code uses the same language (say C#) you can organize it all in one project, resulting in one exe file, zero dll files.
The main reason for dll files is to support reuse (either Controls that can be added
to Visual's toolbox, or general classes e.g. for numeric algorithms, graphic library,
encryption, whatever). Once you have the dll, and some knowledge about it, you can
create new projects that make good use of it. And so can others.
A secondary reason to use dll files is for mixing languages (say C# and VB.NET).
If you want to protect your intellectual property, putting it all in a single exe is
only a small improvement, since .NET byte codes can be decompiled with tools such as
Reflector, wheter in dll or in exe.
|
|
|
|
|
Thanx
i added all dll source code into main project.
I created this dll files to reuse just by me. but i cannot allow this files can be used by someone. I mean
how could i restrict this?
adding Strong key is a solution?
or GUID number?
or what is the best solution.
|
|
|
|
|
Hi,
I dont really know; you can make it more difficult for others to use a dll, by giving
it a complex API, with methods that need to be called in a specific order, with
extra arguments that must match some criterium, etc, but using a tool such as Reflector
one can always see how you do it.
A strong key will not help, it is intended to prevent someone to use a different
dll underneath your exe in order to falsify your app. That's not what you are after is it ?
|
|
|
|
|
I'm writing a multithreaded application, and in some phase in my program i have to add
a row to the datagridview control from thread other than the thread the control created
in, but when using this line of code
Control.CheckForIllegalCrossThreadCalls = false;
when the rows count comes out of the datagridview control visible area,and then try to
add a row the program stuck on screen (NotResponding).
so i want to know how to call an invoke method on a datagridview control to add a row?
in order to make the call a thread safe.
thanks in advance,
|
|
|
|
|
Hi,
the InvokeRequired property and Invoke/BeginInvoke methods work the same on all controls,
you can find many articles about that subject.
Both of my articles also show a very simple example; I recommend you look at MainForm.cs
in the Sokoban article.
You must follow the rules here; if you dont, it may or may not work on .NET 1.x
(not work here means freeze); on .NET 2.0 and above, it will throw an exception.
|
|
|
|
|
|
Hi, I keep getting the error "The requested URI is invalid for this FTP command." when trying to upload a file from local machine to the FTP server using code below in C# 2.0. I am getting error on the bold line below.
I would appreaciate if someone can guide me to proper solution.
thanks
Mahesh
public void Deliver()
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(destinationHost); //destination host is ftp://actual IP address/
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(userId, password);
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(sourceDirectory + sourceFile);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream(); //getting error here stating requested uri is invalid for this FTP commnand.
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
}
Thanks
Needy
|
|
|
|
|
First,I'd like to thank you for this great effort
how can I shutdown and restart my computer from my app
Dad
|
|
|
|
|
Hi.
You can use WindowsController class, which you can find here: http://www.mentalis.org/soft/class.qpx?id=7
It's really easy to use, for example to shutdown your computer, just write:
WindowsController.ExitWindows(RestartOptions.ShutDown, false);
In file with this class, you'll find simple example.
-- modified at 16:58 Thursday 1st March, 2007
|
|
|
|