|
I got it done, thanks if you read it.
|
|
|
|
|
Hi,
With my datagridview I have column for datetime. I used the following for format.
Dim secidexp As New DataGridViewTextBoxColumn
With secidexp
.MaxInputLength = 10
.DataPropertyName = "sec_id_expiry"
.HeaderText = "ID EXPIRY DATE"
.DefaultCellStyle.Format = "dd/MM/yyyy"
End With
But the problem is it's getting input like MM/dd/yyyy and after pressing enter it's changing to dd/mm/yyyy style.
So is it possible to get input like "dd/MM/yyyy"
PS: This Problem occours only in Editing the rows & for New Rows.
Thanks ...
|
|
|
|
|
This is probably dependent on the culture info of the computer. Look into setting the culture info for the datagridview. I'm only guessing as I generally don't allow data entry into a grid control, I force the user to a details dialog for data manipulation where you have much finer control.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Basically, my goal is to get a multiline TextBox or a RichTextBox to resize the font of its text until all of the text can be seen. The following code works to make the text fit on one line, but I am not sure how to change it to work for multiple lines.
Public Shared Function BestFontSize(ByVal g As Graphics, _
ByVal z As Size, ByVal f As Font, ByVal s As String) As Single
Dim p As SizeF
p = g.MeasureString(s, f)
Dim hratio As Double = z.Height / p.Height
Dim wratio As Double = z.Width / p.Width
Dim ratio As Double = Math.Min(hratio, wratio)
System.Console.WriteLine(f.Size * ratio)
Return f.Size * ratio
End Function
Private Sub TextBox1_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text <> "" Then TextBox1.Font = New Font(TextBox1.Font.FontFamily, _
BestFontSize(TextBox1.CreateGraphics, TextBox1.Size, TextBox1.Font, TextBox1.Text))
End Sub
Is there a way to determine which characters are actually visible on screen? Any ideas on a better way to do this?
|
|
|
|
|
I've done soemthing like this before. Basically, there's no function that will do this for you and no way to tell what has been drawn and what hasn't. What I did was use MeasureString with a starting font size, see if it fit in an available space, and if not, reduce the font size and measure it again. Keep going until you reach either a minimum acceptable font size or the drawn text finally fits.
Warning! This method can be slow and reduce your app's performance.
In a second version of the app I did, I ended up drawing the text to a bitmap in a fixed-size, but larger, font, then drawing that bitmap to the screen scaled to the proper size. The final drawn text quality suffered a little bit from the scaling, but the performance was much better.
|
|
|
|
|
Hi,
this is what I would try:
0.
choose fontsize fs1=10;
1.
use Graphics.MeasureString() with some font (fontsize fs1), the right width, and let it compute the height that would take. Make sure to give it all parameters equal to what you will use in the TextBox eventually.
2.
calculate a new fontsize as fs1 = fs1 * 0.9 * textboxHeight/measureStringHeight; (use floating-point!)
3.
since with a different font size word wrapping will be different too, iterate steps 1 and 2 say three times. (The 0.9 factor above is there to reduce the likelihood final text does overflow just a bit)
|
|
|
|
|
i am developing one eform designer project..the main object of this project is there a form in this controls are drag and drop.moving and deleting and editing the properties ..it's like a our .net designer how we drag and drop the controls ..so in my project i need to implement undo/Redo functionality..please give me the basic idea of this..(Please think like a our .net Designer (UNDO/REDO))
Thanks & regadrs
Dilip
|
|
|
|
|
Take a look at this blog[^], and see if it meets your needs.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I would personally have a structure which a) describes what the user did, or b) describes the state of the control before the user interacted. Then I would use a Stack, and just push or pop the structures whenever the user clicks Redo or Undo respectively (I think)
|
|
|
|
|
You may want to do some research into the "command pattern".
|
|
|
|
|
I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired.
Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine.
Any solution of this problem?
Thanks.
|
|
|
|
|
Maybe you could set a boolean flag which gets toggled when the user enters/leaves the textboxes on your form. The x key routine would then check the state of the boolean flag which would determine if the event should go ahead or not.
|
|
|
|
|
Thanks Liqz,
The situation is there is one main form and depending on menu items selection, it is loading user controls on main form, which comes from multiple solutions. So there are many solutions and lots of user controls are taking part here.
I do not want to change all the user controls but I want to change only main form.
Thanks.
|
|
|
|
|
Take a look at Tom's post below, it is actually a better solution than mine, I was unaware of the ActiveControl method.
Using that method you can get the type of the active control, then if the type of active control is a text box, don't do the x key function.
|
|
|
|
|
Use alt+x ?
Other than that in your function (that is called by the event handler on pressing x) check if the current active control is one where the user can type in (textbox, richtextbox,...)
This might be off help:
form.ActiveControl
|
|
|
|
|
Thanks Tom,
I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination.
Also I looked on ActiveControl but the deal is I have layers of controls like this:
Bottom to top
Form
User Control
Split control
User control
Textbox and other controls.
When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls.
Any help please?
Thanks.
|
|
|
|
|
Hi,
the KeyDown event offers a KeyEventArgs object containing information about the most recent key, but also the current state of the modifier keys such as Alt, Control, Shift.
|
|
|
|
|
If the alt+x way is a valid way to go for you I would do it that way, since you have usercontrols the activecontrol will most likly never be to accurate.
This code works fine for me:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt = True And e.KeyCode = Keys.X Then
MessageBox.Show("success")
End If
End Sub
Property 'Keypreview' from the form set to true
If you don't get it working like that I suggest you create a menustrip on the form, add a dummy menu, in the properties of that menu add a shortcut (alt + x), set the property 'visible' from the menustrip to false and do your function in the click event of the menu. (always works that way)
|
|
|
|
|
I am currently writing a program which allows users to crop an image by drawing a box on the displayed image. The control I am using is picture box. Now, the crop function is acheived by defining a rectangle and pass through Bitmap.Clone. all the cropping and saving function works fine, but the biggest problem I am having is the users I am working with deals with very high resolution images, somewhere in the lines of 2500 x 3500. Therefore to display the whole image onto the screen I am using either a SizeMode of Zoom or StretchImage, however this causes a problem when cropping the image. When the image is cropped it is not at the region specified by the rectangle, it ends up cropping a different portion of the image.
I cannot use SizeMode AtouSize either as the user must be able to see the entire image and the cropped area of the image must come from the original high resolution image. If anyone knows a solution to this problem or can point me to the right direction I would be most grateful.
Thanks in advance.
|
|
|
|
|
Hi,
the problem basically is that the PictureBox is doing things (panning, zooming, resizing, ...) to your image, and not to whatever you draw on top of it.
There are two solutions:
1. mimic the PictureBox logic for everything you are drawing on top of it.
2. don't use a PictureBox at all; use a Panel instead, show the image by painting it with Graphics.DrawImage; now implement the panning, zooming, resizing,... whatever you want yourself and apply them equally to the image and the other parts drawn (best use one or some of the Transform methods which manipulate coordinates and scales).
I always do (2), there is no benefit in trying to mimic a PictureBox when it works against you.
|
|
|
|
|
Thanks for the reply, but I think using Graphics.DrawImage to paint the image on the panel isn't going to work for me, perhaps I should explain my intention more clearly. What I want to do is allow the user to crop their high resolution image, but the entire image must be displayed on the form without parts of it cutting off, in order to do this I have scale down the image to best fit the picture box and keeping the SizeMode to Normal. However, when the user crops the image the crop must come from the high resolution image itself but not the scale down version displayed in the picture box. I have managed to achieved cropping the right portion of the scale down version of the image, but obviously cropping the scale down version will mean that I will lose the original resoultion and keeping the high resolution is an absolute requirement for this application.
Correct me if I am approaching this the wrong way, but my thinking is that as the user draws the rectangle on the scale down version of the image, instead of the passing the scale down version through Image.Clone or Grahics.DrawImage, the orignal high resolution version is passed through instead and there needs to be some sort of code that proportionately scale up the rectangle drawn so that what ever section that the user crop on the scale down version will match the high resolution version. I don't know if it is possible to acheive this nor do I have any idea how to approach this, any help will be much appreciated.
Hope all this make sense, thanks in advance.
|
|
|
|
|
Hi,
First of all anything a PictureBox can do you can do wiith a Panel, the difference is when drawing yourself you are in charge.
look carefully at the Graphics class; its DrawImage method will paint an image and its DrawRectangle will paint a rectangle. Both will use the same coordinate system, which you can freely choose.
If you apply a transformation (TranslateTransform, ScaleTransform) it will:
1. apply to everything you draw afterwards
2. allow you to position and scale everything so that e.g. part of your image falls outside the panel.
So you can scale down a 1000*1000 picture and a 900*900 rectangle to a 100*100 panel; have the arrow keys move the (unscaled) rectangle move by 1 pixel in real coordinates (hence 0.1 px on the screen), etc.
|
|
|
|
|
I suspect that Luc is probably correct in his reply to your question.
I have been caught out in the past when doing this sort of thing, and you might like to bear in mind, that not all images are saved at the same resolution as your screen. I use 96 ppi and have had problems with images saved at 72 ppi. Of course stretching/zooming the image will cause more problems, but this might become relevant when the selected region is small enough to display in its entirety.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: I suspect that Luc is probably correct
Thanks for the endorsement.
|
|
|
|
|
I want to list security groups of several folders in my windows 2003 server.
Is there anyway that i can do this without doing manually?
dsquery can do this ,,please someone post the query ?
modified on Tuesday, April 28, 2009 8:07 AM
|
|
|
|