|
Does anyone know how to get Graphics.MeasureString to take into account whitespace (spaces and tabs namely) at the ends of strings? I tried feeding it a StringFormat object with the Trimming property set to StringTrimming.None but no dice. What am I missing?
|
|
|
|
|
If you read the documentation for the StringFormat.Trimming property, you'll see that it controls how strings are trimmed if they lay outside of the clipping region. It has nothing to do with trimming the whitespace on strings.
See the StringFormat.SetMeasurableCharacterRanges to specify that whitespace characters should be included when measuring.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox
top secret
|
|
|
|
|
Thanks ya'll! Works like a charm!
|
|
|
|
|
I have a situation where I wanted to expose the properties of a constituent control(TextBox in this case) of my user control in the property grid. I found this to be very simple by just making a public property for my TextBox and works fine. The problem is that it doesnt write the changes of the TextBox state to the code file. If I expose they properties of the TextBox directly off the user control it does save them to the code file. I guess my question is would be: Do I have to expose every property of the constituent control on the user control to get it to generate the code or is there a work around. Someone please point me in the right direction
|
|
|
|
|
The code is generated to get/set properties on your class - the container class in this case. It would set your property to whatever text you use. When the code is executed, your property is set at runtime which sets the property on the TextBox . If you're looking for a way to control the code generation so that setting your property actually serializes the code so that the child TextBox is set, you're not going to find an easy one and I'm not sure it's even possible since VS.NET (or any designer, like SharpDeveloper) is what provides the code serialization implementation.
As far as exposing all the properties of a child control, you need to decide what you want to expose to the user. The whole idea of a complex container control is to encapsulate other controls as you require. If you end up exposing all the properties of a child control, then what's the point of encapsulating it in the first place?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If you want them to be able to design your control in such a way, you'll need to extend ControlDesigner and provide full designer support for your control. As far as the properties go, though, my original reply still stands. The form/control designer is designer your control, not the child controls. When a property is set on your control, it will serialize the code by setting the property on your control, not the child controls which it knows nothing about. It still won't really make a difference, though, since your properties are basically reflecting the values back on the child controls' properties.
Getting a designer to do this will still be tricky, though. You can extend your designer by providing this type of functionality but getting it to serialize the code appropriate is another matter. Read through the documentation for the ControlDesigner and related documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an application, that needs to have a settings dialog. I want the settings to be available to the rest of the application all the time, even when the settings dialog is closed. In other words, this dialog is merely a utility for the user to modify these settings and save them.
I'm thinking, I should have the settings struct, so that it's a value type, which doesn't need instantiation to be used, and be available all through the application lifetime. Now the challenges are:
1- What's the best method to load/save this struct? Can XML serialization work here? If so, how?
2- Can I bind the struct's fields/properties to controls on the settings dialog, so that any modification will automatically reflect in the struct, which, in turn is the one responsible for actually loading/saving all the settings?
Thank you.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
A singleton pattern works well for this. We use a PropertyGrid for the time being in our application. I create a singleton that uses a collection of classes implementing the ICustomTypeDescriptor and gets everything from a database. The application allows the changing of these values while callers throughout our application have a simple means to get these values. Just put the classes in an assembly that is shared and used by all the assemblies in your application. I put ours, for example, in our toolkit assembly.
XML Serialization would be a good way to read and save your preferences. Just see the System.Xml.Serialization namespace for all the attributes you can use, as well as the XmlSerializer that does include a sample of how to use it. It's really very simple.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
singleton pattern
I'm sorry, but I don't know what that is
Heath Stewart wrote:
Just put the classes in an assembly...
So you do suggest classes instead of structs? I read in an article on CodeProject before by Nishant that whenever you find that you're using a class merely to store values, it's better to use a struct. Comments?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
A singleton is a single instance of an object. You can either use a simple approach like:
public sealed class MySingleton
{
private static MySingleton instance;
private int i;
private MySingleton()
{
i = 1;
}
public static MySingleton Instance
{
get
{
if (instance == null)
lock (typeof(MySingleton))
if (instance == null)
instance = new MySingleton();
return instance;
}
}
public static int SomeMethod()
{
return Instance.i;
}
} Or you could use a ContextBoundObject with its own RealProxy derivative that returns the same instance when someone tries to instantiate your object.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
please some one tell i have a barcode scan device and i wanna to write a code using c# to get the barcode from the barecode device
i will make that by making a thread in my code to detect any input from the barecode then:
_how to make that connection between my code and the barecode device so that user can input the serial of any product from the keyboard (by manualy focusing at text box) or from the barecode device (without focusing at any thing)
please some one can help me in that senaro i wanna just an overview idea about how to make that way of code
::::tonaxxl:::::
|
|
|
|
|
You already asked this question and got the answer to it.
It all depends on how you barcode scanner works. If it injects data into the keyboard stream, then all you have to do is make sure that the focus is on the textbox. If it sends data to the PC through another means, like the Serial Port, then you'll have to write a communication class to handle that kind of input.
It all depends on the barcode device and how it sends data to the PC...
RageInTheMachine9532
|
|
|
|
|
If it sends data to the PC through another means, like the Serial Port, then you'll have to write a communication class to handle that kind of input.
:::::then how to make that communication class that listen to the serial port ?
i wanna to find the way to to connect to that serialport
i dont know how to make that
|
|
|
|
|
First thing's first...
The make and model of the scanner would be helpful.
Do you have all the docs on the scanner? Do you know the communication requirements of the scanner? Do you know what format the data comes in? Do you have the commands the scanner understands? The formats of those commands?
If not, your wasting your time...
RageInTheMachine9532
|
|
|
|
|
no i have nothing from what u say but i wanna the whole story of using the barecode if have a breif idea about the way to handle the barecode numder from the any kind of serial barecode scanner i dont know any thing about that stuff and i ask any one to help me by him self or by sending me any url to help me in that stuff
and i search and found all the code write in that is for the way to print the barecode but i wanna to input it and how to handle it
thank u and i hope i make my self more clearar
|
|
|
|
|
If you don't have any of that information, you're going to have VERY difficult time doing this.
Basically, all you've told use is that you have a barcode scanner and that you want to write a program. You haven't given us ANY information to work with, yet you want help with writing code.
All I can tell you is to search the web for code samples, search for the manufacturers website and search for the technical docs on the scanner.
You can start with the code in the previous post for Serial Comm in VB.NET and you can also look at the VB6 code here for a barcode scanner example. Don't know if it's going to work for you because you haven't been able to tell us what barcode formats the scanner can read.
http://www.vbexplorer.com/vb/scripts/ShowCode.asp?txtCodeId=47696&lngWId=-1[^]
RageInTheMachine9532
|
|
|
|
|
i need any code example i mean it i need any example
but with the c#
and i need a brief flow chart of how this any serial port
barcode device should be used
all what i need is a brief flow chart with sample of code if possible
|
|
|
|
|
There is a VB6 example here[^]. I can't find any .NET examples anywhere.
RageInTheMachine9532
|
|
|
|
|
thank u so much for ur effort with me
|
|
|
|
|
hi,
in order to help you, you should have a look at this tut -> http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320
that's all you need
|
|
|
|
|
thank u man so much that is so helpful that what i need
from where r u
?
|
|
|
|
|
I just finished a point of sale system for my universities bookstore. I had a choice of scanners and choose the keyboard wedge scanner. It is the easiest to incorporate into the system as there is no special coding involved. I simply plugged it in, programmed the scanner with the neccessay, and supplied, barcode initializations, and then scanned a code. Sure enough it placed the numeric representation of the code in the textbox that had focus at the time. No special interface coding needed.
I would suggest you look into a keyboard wedge type of scanner.
Joe
|
|
|
|
|
I'd liek to include a couple icons in my EXE file to associate with different file types. I'm having trouble adding the icons to the EXE. I have a program which will extract icons and give me the index number so I can make the entries to the registry, but when i add the ICO file to thwe project and build (both as content and Embedded Resource) only the mail icon is detected when the EXE is examined for icons. Any help would be appreciated.
|
|
|
|
|
Icons cannot be embedded as resources in your assembly and be visible to windows. Keep in mind an assembly - while sharing the same extension as a native library (DLL) (and the PE/COFF header which minor differences) - is much different.
These icons must be in the .rsrc section of your PE/COFF executable. One way to do this is - after you compile your library or application - open it with Visual Studio (as a binary resource) and you'll see the various sections of the .rsrc section, like the VersionInfo block. You can import your icons there and give them resource IDs (if you'd rather refer to them by their resource ID rather than their index). If you've signed your assembly - and any production assemblies should be signed - you'll have to resign them. Typically, it's better to delay signing (see AssemblyDelaySignAttribute ) till after you make these kinds of changes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|