|
Hi,
to provide an acurate display, the operating system needs to know the resolution of your monitor.
For MS Windows (XP and others) the default value is set to 96 dpi, which used to be a good
average value before, but may be well below the actual value for a modern monitor.
The theoretical value you need equals the length of your monitor's diagonal in pixels
(this is the square root of horpixels squared plus vert pixels squared !) divided by
same diagonal's length in inches (14, 15, 17, 19, whatever).
Examples: 17 inch monitor with 1280*1024 pixels gives SQRT(1280*1280+1024*1024)/17 = 96.4 dpi !
but 15 inch monitor with 1400*1050 pixels gives 116.7 dpi
To change the setting: right-click the desktop, choose Display Properties, click Advanced button, and look for the DPI Settings combobox. The custom setting is expressed in % not in dpi,
so whatever you calculated you should multiply by 100/96 to get the right percentage.
Warning: if you never cared before, and now increase the dpi setting, every item on your
desktop will become smaller, but it is a required step to get acurate dimensions.
Remark: to counteract the reduction of font sizes, you can ask Windows to use larger fonts
on the desktop (see Display Properties, Appearance, Font size); you can also ask it to use
larger icons...
Luc Pattyn
|
|
|
|
|
Dear Luc:
Thanks for your post!
If I know the resolution and size of the target monitor, I can write the program easily and everything can be calculated correctly. But that's hard-coded. The question is that the program will run on different machines without knowing the resolution and size parameters in advance. The program must automatically figure out the resolution and size of the target monitor. How can I do that?
Sheng
|
|
|
|
|
You have missed my point. There are two steps involved:
1) you tell Windows what your resolution is, see my previous message (for each monitor
and each monitor involved). This is independent of any application.
2) your application(s) asks Windows what the resolution is, see a previous message by Ravi
(on Graphics.DpiX and Graphics.DpiY; which as far as I know, and unfortunately, always
will report identical values, since Windows is only interested in a single, diagonal,
resolution)
So there are no constants in your applications, but you have to calibrate each Windows
system once.
Luc Pattyn
|
|
|
|
|
Luc:
Thanks!
Is there any method which can programmatically read the horizontal and vertical physical dimension information of the target display from the Windows system?
If the program can get the physical dimensions at run time, the program can of course programmatically control the real physical dimension of the drawing.
Sheng
|
|
|
|
|
You need a Graphics object:
normally you get this in your Paint method, from PaintEventArgs.Graphics
alternatively you may have a look at Graphics.FromImage()
Luc Pattyn
|
|
|
|
|
Graphics.FromImage() does not provide the physical size infomation of the display.
Sheng
|
|
|
|
|
On my system, the following code prints "DpiX=135":
Bitmap bitmap=new Bitmap(100, 100);
Graphics gBM=Graphics.FromImage(bitmap);
Console.WriteLine("DpiX="+gBM.DpiX);
Luc Pattyn
|
|
|
|
|
I want to know which one is better. I see a better benefit on scripting, since any change on the database will enable you to change some code. Here is what I am talking about
Assume that I arleady know the database. For instance, I want to connect to an company database to read some information about employee names. Now, I can have a sample of that database and use a wizad to do that. Or I can use the oldbconnection and use sql command to do that. What I like with the wizard, is the fact that every field from the database can be pulled up with intellisense. And very easy to connect those field or the database to windows form component.
The problem I see in the wizard, if you don't know much about that dabase in advance and whant to read some field on it. I also see more people or book use the scripting than the wizard.
Anyway, all what I want to know which one is better to use; the database wizard or the sql command string which is related to ado.
|
|
|
|
|
I have a form where I don't want the user to edit any of the fields in the form - readonly. I set the panel.enabled to false. The fields are hard to read as they are light grey. Does anyone know how to change the .enabled font or a better way at doing this.
Thanks for everyones help.
|
|
|
|
|
the controls on the panel are are disabled because their value is set by their container. You might be able to override the graying of the text, by reseting the forecolor of hte controls to black after the panel is disabled. This is just a guess though, not something I've tested.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
well friends I'm a new bee to crystal reports here. Just started to work after reading a few articles from codeproject.com
what I wanna know is that can we show a picture from our database in to the crystal report. if yes... how?
oh by the way I'm using .net 2.0 and I think it must be crystal report 9 or something what ever comes with it u know.
thanks in advance but plz dont tell me its a C# forum.. I know that
Rocky
|
|
|
|
|
hi guys
i posted earlier about an app i am developing for making DFD's . I have
made something at least but the problem here is that when i deploy the
application its behavior changes.
first the features:
1. you can make a Data Flow Diagram.
2. Save it
On saving three files are created
a. file 1 is .bmp file which is the image of your DFD.
b. file 2 is an XML file which shows the logical meaning of this
DFD, in my self defined schema , if you want to know it ask me i
will explain but here i m too lazy to explain.
c. The third file is a..dfd file which is a custom extension
defined by me for saving the DFD,this is also an XML file , it is used
for saving and reopening the DFD for editing and is pretty self
explanatory.
3. you have to drag drop objects on work area and click line to draw a
line from one to another.
4. you can move lines , delete them , move delete objects,etc.
5. The lines move along with the objects and resize themselves.
6. As DFD's are all about data flow , you can drop labels onto the work
area and name the lines (these will be saved in second XML file), drop
them on line.
7. you can compile DFD's and it show if any errors there, to understand
that you need to know DFD's,check out wiki.
8. you can print them and save them as another one and stuff like that.
features to be added
1. real time compilation .
2. real time adjustment of lines as you draw them.
3. Multi level DFD's and if possible , i 'll try to generate some code
too
suggestions are welcome
You can get it here
http://www.esnips.com/doc/7bd44a49-dfe3-46bc-a157-a9b1d9d3c2ca/Release.rar
Now the problem , the problem here is that when i am debugging this
project the double buffering thing works fine , but when i deploy it
you will notice when you put a label on line and move objects( boxes ),
the lines start disappearing, in debug as well as release exe, please
guys help and to do post some reviews
Sameer Sood
Microsoft Student partner
NIT Durgapur,india
|
|
|
|
|
I'm starting to fiddle with COM Interop within my C# code. I've managed to get MS Word embedded within my form and am able to remove it's caption and resized it to fit within the child area. The problem Im seeing is if I restore the caption and attempt to maximize the child (MS Word) it doesnt maximize to the max boundaries of the child area as expected but in fact just dissappears from view. I've even hid the caption and used Word's menu item (Window >> Arrange All) and this time the display remains in view but the lower portion and right side are cut off from view (the overall window appears sized beyond the child bounds).
Perhaps my reasoning of parent child relationship is incorrect when it comes to windows. Here is a portion of my code for establishing the relationship and resizing:
// Win32: Use SetParent to set the handle to the Word instance as a child to my form
SetParent(WordHWnd, MyForm.Handle.ToInt32());
// Win32: Readjust the position of the word window -- Seems redundant to MoveWindow though
SetWindowPos(WordHWnd,MyForm.Handle.ToInt32(),0,0,MyForm.Bounds.Width, MyForm.Bounds.Height, SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME);
// Win32: Move the window into view
MoveWindow(WordHWnd,0,0,MyForm.Bounds.Width, MyForm.Bounds.Height,true);
// My function to remove the caption.
RemoveCaption(WordHWnd, MyForm.Handle.ToInt32());
// Win32: Maximize the Word Window to fit the full area of its container
ShowWindow(WordHWnd, SW_MAXIMIZE);
|
|
|
|
|
How can I prevent items from an outside location from being accepted as drops? I'm making a dialog to move items between two listboxes, and need to keep external strings from being dropped into either.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Do checks in the OnDragOver event.
|
|
|
|
|
Where am I supposed to get the data to identify the source from? sender is the potential recipient, and DragEventArgs doesn't have a member indicating the souce.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Encapsulate your strings in a custom IDataObject impementation. When you check for the correct data type in your DragOver and DragDrop events, you just look for data of that custom type. If it's not there, well, you know you're getting data from an unauthorized source.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thank you.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
It appears I don't need to implement a custom IDataObject, just a custom type to put into the stock DataObject that gets passed around. Much less work this way.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Whatever works! I just thought of it off the top of my head. I never said I did it myself!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
No worry, without your idea, I'd've probably spent more time searching for what I ended up doing than I lost starting to implement the innerface.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
I have a web page where the user selects a month and year and submits it to the system.
I then need to create two dates - the first and last dates of that month - which are then sent to another page.
Whats the best way to do this ? I came up with the idea of subtracting the month from todays month, doing the same with the year and then creating the start date.
But this involves converting a string -> int -> date and then back to string - which seems like a lot of converting.
|
|
|
|
|
Use the DateTime.DaysInMonth to get the number of days in the month. Then you can easily create DateTime structures from the values, and format the dates as you like them.
---
b { font-weight: normal; }
|
|
|
|
|
This looks suspiciously homeworky . Anyway, here's the easy way to do it:
DateTime startDate = new DateTime(selectedYear, selectedMonth, 1, 0, 0, 0, 0);
DateTime endDate = startDate.AddMonths(1).AddDays(-1);
You can use a similar trick to get the first and last days from any date:
DateTime dt = new DateTime(2006, 11, 26,0,0,0,0);
DateTime startDate = dt.AddDays((-(dt.Day)) + 1);
DateTime endDate = startDate.AddMonths(1).AddDays(-1);
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
In some codes I saw @ character before string. I here that it is used in php sytax for breaking loops, but could not found any clue what it does in c#
karanba
|
|
|
|