Images move basis on fields in C# - c#

(https://i.stack.imgur.com/KojcD.png)
Problem: I have to move images according to the textfields or label. In this problem when I hit enter button (for next field) and KeyUp (for previous field), I want to also move according to the fields move. Please help ?

Related

Holding down arrow keys in DataGridView not moving cursor smoothly

If I press and hold down either the UP or DOWN arrow key when focused on a DataGridView, the cursor (blue highlighted cell) doesn't move evenly down the rows, instead it jumps several rows at a time in batches. Sometimes it doesn't even seem to move at all until the key is finally released, then the cursor jumps directly to several rows ahead having presumably stored all the key presses.
Here is a GIF image showing the behaviour when pressing and holding the DOWN arrow, then releasing it and pressing and holding the UP arrow.
This movement looks wrong and makes it hard for the user to judge when to release the key to navigate smoothly over several rows. It doesn't even seem to move an number of rows on each jump it makes (like 10-20 rows on each jump, sometimes the whole page, or even reappearing many rows beyond when the user finally releases the key).
For example if the user wants to move the cursor about half way down the page, by pressing the DOWN arrow key and holding it down, then it is very hard to know when to release the key because the cursor is not moving down in an even progress.
Why doesn't it visibly move to each row one at a time in a smooth repeating manner, instead of doing ugly hopping over batches of rows?
This can be reproduced as follows:
Make a new forms project.
Drop a DataGridView control onto the form.
Add a DataGridViewTextBoxColumn in the designer.
Add some rows to the DataGridView, and add a little formatting to make enough rows visible for your test, in the FormLoad event:
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.RowTemplate.Height = 14;
dataGridView1.Rows.Add(50);
dataGridView1.Dock = DockStyle.Fill;
}
Then run the program and press and hold the DOWN arrow key to see how the blue highlight jumps down strangely instead of moving smoothly down from row to row.
The strange behaviour exists even when the DataGridView is read only.
I have tried making the grid and the form DoubleBuffered but no success. I have also tried setting the grid to Virtual mode and ReadOnly and changing just about every setting of the grid, but nothing works.
The only way I have discovered to make the cursor to move smoothly and rapidly up or down the rows without jumping over batches of rows, has been to not let the DataGridView be focused. To do this I make another control on the form (for example a textbox, and give focus to the text Box). Then I override the processCmdKey method on the form to capture the keyboard input and if it detects an arrow key then I programmatically change the current cell in the DataGridView (for example to the next row if the DOWN key was detected in processCmdKey). This moves the current cell without ever giving actual focus to the DataGridView. The movement of the highlight then appears to progress evenly and doesn't jump down in strange batches.
Add a text box onto the form
Add this code to the form:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
int currentRowIndex = dataGridView1.CurrentCell.RowIndex;
switch (keyData)
{
case Keys.Up:
// Check not already at the first row in the grid before moving up one row
if (currentRowIndex > 0)
dataGridView1.CurrentCell = dataGridView1.Rows[currentRowIndex - 1].Cells[dataGridView1.CurrentCell.ColumnIndex];
return true;
case Keys.Down:
// Check not already at the last row in the grid before moving down one row
if (currentRowIndex + 1 < dataGridView1.Rows.Count)
dataGridView1.CurrentCell = dataGridView1.Rows[currentRowIndex + 1].Cells[dataGridView1.CurrentCell.ColumnIndex];
return true;
}
// Line below is reached if we didn't handle the key in this method, it tells the form/control to handle it
return base.ProcessCmdKey(ref msg, keyData);
}
Then run the program to test again as follows:
Click on the text box to give it focus (instead of the grid). Then press and hold the DOWN key, to see that the blue highlighted current cell progresses smoothly down through the rows. Release the key.
Then click on the grid to give it focus, then press and hold the UP or DOWN arrow key and witness the blue highlight jumping across several rows instead of progressing smoothly.
So the problem exists whenever the DataGridView has focus, regardless of whether the grid handles the keys presses or if I handle them in processCmdKey.
I don't want to rely of keeping focus away from the grid, because there are times when a grid needs to have focus. I'd also have to add a lot more code to processCmdKey to handle all the other potential key presses for a grid, such as tab, page up / down, enter etc., which doesn't seem sensible.
The grid will actually be read only in my application, so it is probably only really the ability to move around smoothly that I need to use, but nevertheless having a dummy control that is focussed instead of the grid doesn't seem sensible.
A slightly similar problem was mentioned here (DataGrid not scrolling smoothly), but it is not Windows Forms and the original poster seemed to state that his problem was fixed by getting rid of all event handling and turning on virtualization, but I've tried virtual mode and I am not handling any events of the grid. He also states that he was on a very busy server. So I think this probably merits me adding this as its own separate question.
Any help would be much appreciated. Thanks :)
The problem has now been solved by changing the keyboard repeat speed settings on the computer. I went to Control Panel | Ease of Access | Change How Your Keyboard Works | Scroll down and choose 'See also: Keyboard Settings'. This then displays a window called 'Keyboard Properties', where I had to lower the 'Repeat Rate', I moved the slider slightly form Maximum (about a quarter of the way from maximum) and clicked apply.
The when I re-tested the program, it worked normally and the cursor moved smoothly down the grid when I pressed and held the Down arrow key.
So I am guessing that there is something strange about my PC that made it not able to cope well when using the maximum keyboard repeat rate, in the case of a DataGridView.
In an ideal world, I'd be able to use a really fast keyboard repeat rate set to maximum, but I am happy enough to settle for a slower keyboard repeat rate in order to solve my problem using the arrow keys smoothly on a DataGridView.
#Sinatr, thanks again for helping me by testing the code on your PC, just telling me that you couldn't reproduce it and that I probably had a problem with my PC rather than my code, was a big help.

Dynamically Surrounding controls C#

In my code I have some pictureboxes that are clicked onto a panel by the user. Wherever the user clicks a picture box is placed. The location is stored in a database so that it can be called back later.
When a user clicks a picturebox it changes the backcolor property to red to give the impression of it being highlighted.
My issue is I want to add a groupbox (or another method of surrounding) around the highlighted boxes. So a user clicks say 4 picture boxes and clicks "Surround" button and it draws a groupbox around those 4 pb's. But I am at a loss since I don't know how to get the location of the outer pictureboxes (the ones that the group needs to surround) since they are all done on the fly?
Any advice would be great.
You probably have the list of all pictureboxes in your application somewhere (if you place them inside a container, that would be Children property). I suggest you simple foreach through all picture boxes and find min/max coordinates, and from there you can easily get the coordinates for the surrounding box. You might be able to do all that using one LINQ query.

Tab key cursor movement between textbox

I have multiple textbox when I press the tab key the cursor move to next textbox, but the my problem is that movement is not sequential or in other owrd is random movement lets say textbox1 textbox2 textbox3 textbox4 the movement is 2,3,1,4 so look how to get the movement back to its correct order
since The control move over to the other on entering TAB according to sequence in which they are drag drooped(or created).
I tried to organize the code in designer but that's does not effect the movement
then how to order the cursor movement ?
is theira code in somewhere to modify according to the order i want ?
Here's a good step-by-step tutorial on MSDN:
How to: Set the Tab Order on Windows Forms

Activereports shrink to fit issue- textboxes

In Activereports ver 7.0,
I have placed 2 textboxes one after another in vertical manner. I assigned particular width and height for both and then programmatically assigning text contents to both textboxes.
CanShrink property is set to true for both textboxes,so the textboxes can shrink to fit based on its contents.
My problem is once the first textbox shrink, I want to move the second one closely to the first one [To remove the extra space generated by shrinking], but it doesn't happen. Why is that?
Please check the image below
Because, the controls only move down, not up during report run. This is by design. In order to accomplish what you are doing, make the textbox1 size very small to begin with, so in essence it will always grow. In case if shrinks with not enough text you can use api to move the textbox2 up (use the location of that control in section format/before print event.

How do I select all text in a groupbox with the mouse?

Ok so I am trying to do something extremely simple but its turning out to be extremely complicated. I wanted to be able to select my text for all of my labels. Since you can't do that I had to convert them all to textbox's. Now that I have that done I want the user to be able to drag their mouse across an area on the form and select whatever text they roll over. A good example would be a web browser.
EDIT
Ok I need to make this a little more clear and what better than some imagery.
Look at the picture above. I cannot drag my mouse across the form to select the text. I have to click inside the TextBox and then I can only select the data that is inside that specific field. I just want to be able to click and drag my mouse over whatever textbox is in my area of selection.
have you "set its BorderStyle to none and set the background color to the color of your form. Also don't forget to set the readonly property to false"
from http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/5ac4267d-2642-4d05-ae84-1562bf16d068/

Categories

Resources