|
Try calling the TextBox.Invalidate() method, this will force the text box to be re-drawn. If that doesn't work then it may be a problem with how you are passing the value into the text box.
Kev Pearman MCP
|
|
|
|
|
Hi,
I am trying to inventory a directorty with Word documents.
This is on of my first programs in VS, but this is what I've got:
Reference to Interop dll's for Word 2002.
Getting the files from the directory.
Opening the word docs one by one.
But then I'm having trouble getting the Toc of the document.
I want to insert the document per paragraph from the toc in a db.
I have read on MSDN but still no luck.
Does anyone have any tips for me?
Steven T
|
|
|
|
|
Hi,
I have some class in my project like Executive, Manager etc. Each class has some perdefined properties like FirstName, LastName etc. I assign the object of my classes to the property grid, to have these perfined properties in the property grid.
The problem is that i want to add some other properties like Address, Phone, Email etc to my classes (Manager, Executive) at runtime, so that these properties can also be accessed through the property grid. How can i do this.
Thanks in advance,
Omar Rehman
|
|
|
|
|
Please I need to know how to get my speed on the network.
|
|
|
|
|
The only way to accurately measure this property is to actually measure it. You need to send data of a known size to a network resource (i.e., your gateway/router or an intranet server) and measure how long it takes to completely send. You should also measure how long it takes to receive this data. You do this over and over again and measure the running average. This is how download managers calculate how much time is left while downloading a file.
You can also use a PerformanceCounter using the "Network Interfaces" category, the "Current Bandwidth" counter class, and the instance of the NIC (network interface card), which performs many of these calculations for you. This is not the actual bandwidth, however, this is only the max bandwidth as reported by the NIC.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm playing around with generics in .NET 2 beta framework.
in 1.1 i have expresion :
propertObjArr[i].PropertyType.IsSubclassOf(typeof(System.Collections.CollectionBase))
to find all properties in object which have been collections at runtime. Then i changed some collection into generic collection.but there is no abstract class for generic collections.My question is how to find out which properties are generic collections.
|
|
|
|
|
nevermind
i found propertObjArr[i].PropertyType.HasGenericArguments solve my problem.
|
|
|
|
|
Hello,
Can any one tell me dat is there a way that i can make my own control box with customized minimize, maximize/restore & close buttons & add this control box to any Form. Is there any class which represents Control Box or do i have to inherit generic windows Forms class or ?????
In short i want to put my own buttons (some fancy styles) where the minimize, maximize/restore & close buttons are on the top right of the form. Ony way is to set the ControlBox property of Windows form to false but then my menus are hidden behind the control box picture which i inserted in order to show a dummy control box.
Please help me out on this.
Regards.
Imran Ahmed Khan.
|
|
|
|
|
There is nothing in the .NET Framework BCL to help you create your own control boxes. You should extend the Form class, override WndProc , and handle the WM_NC* notification messages to draw in the non-client are of the window frame. There are many native APIs that you must P/Invoke, as well as many supporting structs you must define (like RECT , which cannot be replaced by System.Drawing.Rectangle - their fields have different meaning).
There are article on the 'net (try a google search) that describe how to do this using C/C++. If you know C/C++, I would suggest creating a Managed C++ project and using both managed and native code to extend the Form class to do what you need. You could then reference that assembly and extend or use that class in any managed language.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
I'm trying to right align a string on a page and i know i can do it if i can find the width of the string i am printing in pixels (or another GraphicsUnit measurement). Does anyone know how i can find this out or does anyone have another way of doing this.
Cheers
Kev Pearman MCP
|
|
|
|
|
OOPS!!
Just read down the forum and saw the previous post on getting the size of a string in pixels.
This should be fine for what i want.
KP
|
|
|
|
|
OK,
i can get the size of the string in a SizeF object using the Graphics.MeasureString method.
The problem i have now is that the page bounds are in 100ths of an inch and i have the size of the string in pixels. My idea was to use the drawstring method and in the place of the x co-ordinate i was going to use:
e.MarginBounds.Right - stringSize.Width,
Obviously this isn't going to work because the 2 values are in different units. Is there a method that i can use to convert a value in pixels to a value in 100ths/Inch or vice versa.
Cheers
KP
|
|
|
|
|
I have a similar problem: I have the size of a bitmap in pixel, but I need to know the size in millimeters.
Some conversion can be done using the PrinterUnitConvert class, but unforunately it doesn't work with Pixel
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
I found this in the book "windows programming with C#" by Charles Petzold:
PointF ConvertMillimtersToPixel(Graphics grfx, PointF pointF)
{
pointF.X *= grfx.DpiX / 25.4f;
pointF.Y *= grfx.DpiY /25.4f;
return pointF;
}
Maybe you can enhance it for your needs...
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
if i convert my page width to milimetres then the above method should work fine.
Thanks for your help, I hope this sorted your problem as well.
Cheers
Kev Pearman MCP
|
|
|
|
|
The correct way is to P/Invoke GetDeviceCaps and query for the logical pixels / physical pixels using LOGPIXELSX and LOGPIXELSY . Hard-coding numbers like the other guy did will not work on every system, especially these days when more and more displays are moving to 120 DPI as opposed to the currently common 96 DPI.
I've posted code to correctly get the number of pixels per some physical unit (twips, actually, which is 1/1440 of an inch) before. See an example at http://www.codeproject.com/script/comments/forums.asp?msg=829941&forumid=1649#xx829941xx[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think it might be worth me re-stating my problem as i'm sure there will be a simpler way of solving it.
I have a string that i am trying to print on a printer, the problem is that the string needs to be aligned to the right hand margin of the page.
I can get the margin bounds, e.MarginBounds.Right , this value is in 100ths/inch i think.
I can also get the length of the string, stored in a SizeF variable
SizeF stringWidth = e.Graphics.MeasureString(myString, myFont); but the values are in pixels as opposed to physical units.
I was hoping to use the following code to print the string in the right place.
e.Graphics.DrawString(myString, MyFont, MyBrush, e.MarginBounds.right - stringWidth.x, Y);
However, this gives the wrong results as one unit is in pixels and the other is in 100ths/inch.
Is there a Method that i can use to convert the stringWidth into 100ths/Inch as this would solve the problem straight away. Or can i get the width of the string in 100ths/Inch straight away, using a different method to the one above.
Cheers
Kev Pearman MCP
|
|
|
|
|
I just told you how and my sample code can convert from pixels to twips and twips to pixels. As I said, a twip is 1/1440 of an inch, so simply divide the number of twips by 1440 to get the number of inches. Multiply the number of inches by 1440 to get the number of twips and convert to pixels.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My apologies Heath, i should have read the example you posted properly.
However the example you posted was really buggy, I have managed to get rid of all of the bugs except for one.
The error i am getting is
The name 'logsPerPixelX' does not exist in the class or namespace 'GMB.Display'
I assume that the error is because you have not included the definition for logsPerPixelX (and also logsPerPixelY).
Kev Pearman MCP
|
|
|
|
|
The error suggest that you need to define the field, but in this case the field name should be twipsPerPixelX , which is already defined but never used. The proper code is:
public sealed class Display
{
static Display()
{
SystemEvents.DisplaySettingsChanged += new EventHandler(Update);
}
private Display() {}
[DllImport("gdi32.dll")]
private static extern IntPtr GetDeviceCaps(IntPtr hdc, IntPtr index);
[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
private static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
private static void Update(object sender, EventArgs e)
{
Setup(true);
}
private static void Setup(bool force)
{
if (initialized && !force) return;
twipsPerPixelX = twipsPerPixelY = 0;
IntPtr hdc = GetDC(IntPtr.Zero);
try
{
if (!hdc.Equals(IntPtr.Zero))
{
IntPtr value;
value = GetDeviceCaps(hdc, new IntPtr(88));
twipsPerPixelX = 1440 / value.ToInt32();
value = GetDeviceCaps(hdc, new IntPtr(90));
twipsPerPixelY = 1440 / value.ToInt32();
ReleaseDC(IntPtr.Zero, hdc);
}
}
catch {}
if (twipsPerPixelX == 0) twipsPerPixelX = 15;
if (twipsPerPixelY == 0) twipsPerPixelY = 15;
initialized = true;
}
private static bool initialized;
private static int twipsPerPixelX;
private static int twipsPerPixelY;
public static int TwipsPerPixelX
{
get
{
Setup(false);
return twipsPerPixelX;
}
}
public static int TwipsPerPixelY
{
get
{
Setup(false);
return twipsPerPixelY;
}
}
public static int FromPixelsX(int x, ScaleMode mode)
{
switch (mode)
{
case ScaleMode.Points:
return PixelsToTwipsX(x) / 20;
case ScaleMode.Inches:
return PixelsToTwipsX(x) / 1440;
default:
throw new ArgumentException("Invalid scale mode.", "mode");
}
}
public static int FromPixelsY(int y, ScaleMode mode)
{
switch (mode)
{
case ScaleMode.Points:
return PixelsToTwipsY(y) / 20;
case ScaleMode.Inches:
return PixelsToTwipsY(y) / 1440;
default:
throw new ArgumentException("Invalid scale mode.", "mode");
}
}
public static int ToPixelsX(int x, ScaleMode mode)
{
switch (mode)
{
case ScaleMode.Points:
return TwipsToPixelsX(x * 20);
case ScaleMode.Inches:
return TwipsToPixelsX(x * 1440);
default:
throw new ArgumentException("Invalid scale mode.", "mode");
}
}
public static int ToPixelsY(int y, ScaleMode mode)
{
switch (mode)
{
case ScaleMode.Points:
return TwipsToPixelsY(y * 20);
case ScaleMode.Inches:
return TwipsToPixelsY(y * 1440);
default:
throw new ArgumentException("Invalid scale mode.", "mode");
}
}
public static int PixelsToTwipsX(int x)
{
Setup(false);
return x * twipsPerPixelX;
}
public static int PixelsToTwipsY(int y)
{
Setup(false);
return y * twipsPerPixelY;
}
public static int TwipsToPixelsX(int x)
{
Setup(false);
return x / twipsPerPixelX;
}
public static int TwipsToPixelsY(int y)
{
Setup(false);
return y / twipsPerPixelY;
}
}
public enum ScaleMode
{
Points,
Inches
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I need tutorials or articles on "Ray Picking" in C#. Anyone of you have any ideas where i can learn from internet? I have download the example form GotDotNet but it is hard for me to understand. I try to search in google but most of the examples in C/C++.
thanks in advance.
|
|
|
|
|
How can I access to an enumeration defined in a class from an instance of another class which inherit from the first?
Example:
public class Parameter {
public enum Something {
...
}
}
public class MyParameter : Parameter {
...
}
MyParameter.Something doesn't work! I think I missed something
regards
|
|
|
|
|
Try base.Something
Hope it helps
|
|
|
|
|
Thank you but I would like to expose the enumeration to the client of the class. Maybe it is more a problem of scope.
For instance, to expose a private member of the base class, I would create a public property but I don't know how to do it for an enumeration.
|
|
|
|
|
public class A
{
protected SomeEnum e;
}
public class B : A
{
public SomeEnum E
{
get { return base.e; }
set { base.e = value; }
}
} You can't access private fields - not even in derivative classes. That's why they're declared as private.
Exposing an enumeration is like exposing any other type, be that a reference type or value type (which an enum is, along with primatives and structs).
Microsoft MVP, Visual C#
My Articles
|
|
|
|