Dock layout issues in WinForms + Devexpress - winforms

I have a WinForms dialog with a lot of DevExpress elements on it.
The form has few SplitContainers and a TextEdit element and DevExpress XtraGrid controls.
All of the controls are Dock=Fill or, in the case of the toolbars, Dock=Top.
When I resize the form it doesn't relayout all the elements, with these results: http://dl.dropbox.com/u/51344/winforms1.png.
It's not until I resize one of the SplitContainers manually that the form relayouts and everything is ok again ( http://dl.dropbox.com/u/51344/winforms2.png ).
I've tried to invoke all of the "PerformLayout, Refresh, Redraw" function I could find in the OnResize event of the form with no luck.
The problem results in even worse layout issues when running in RemoteDesktop.
Does anyone have an idea how to debug this issue?
Edit:
I hate to answer my own question, been battling with this on and off for few days.
This ugly piece of code seems to do the trick. Resize the splitcontainers by one pixel to force a re-layout:
splitContainerControlQuery1.SplitterPosition += (splitContainerControlQuery1.SplitterPosition % 2 == 1) ? 1 : -1;
splitContainerControlQuery2.SplitterPosition += (splitContainerControlQuery2.SplitterPosition % 2 == 1) ? 1 : -1;

Related

How to Move content to next page in WPF Form

I am new in WPF if there is something wrong please co-operate.Here i require some idea from experts.
I am working on one application in which i have to show some content on WPF form after filling the fields present on the form.On the same form i also have a print option.
Check this image.This is my form here part in the red block is generated at runtime.When i click on the print button it only show the visible part on the paper and skip the remaining part.
Problem :
How i can move the remaining part of the form which is under scroll to next page when i click on print.
For example in the given image we can see only 2 bulls eye completely and next 2 partially.How i can shift this remaining part to next page only when i click on print.
The answer is quite easy : don't rely on your window to do the printing, but build the visual you want then print it.
For instance, you must have a function that creates dynamically the circles and so on, then adds them to a Panel. What you might do is to print the Panel.
Or if you prefer, you might build Dynamically a new window, where you put all the Data you want printed as you want, then print the window. The advantage of this method is that it is more flexible for the content (if you want a header/footer) and also you can watch the content easily for debug. Note that even if the Window content is dynamic, you can have a base window for printing that avoids you to do too much xaml with code (expl : you might have TextBox bound to a PrintTitle property that you setup in the constructor of the Print Window...).
Notice that visual that were not rendered on screen will not print. Be sure, to avoid the common issues, to have a look at this article from this great site, switch on the code, here :
http://www.switchonthecode.com/tutorials/printing-in-wpf
Edit (reply to the question in comment):
1) If you have fixed number of bulls eyes, just make one Window for that number and Print it, this is waaaay easier.
2) To put Visuals in pages instead of rows, you'll have to rely on page Width/Height. What matters is the size of your control vs size of page. In the example, they build (in OnRender) Controls having LineHeight, LineWidth as size. Do the same : Try to put as many line of control as you can such as
(Control Height + margin )*NumberOfControlPerPage < Page Height.
Then you have to change OnRender to render controls instead of Rows made with rectangle+text. Pack your controls two by two in Horizontal StackPanels Then pack those StackPanel into a vertical StackPanel, then render. You have to keep track for each page which control was rendered last, then resume rendering at the following control.
Please follow this link.This is the basic which i got after searching in web world.Using this basic detail you can do any thing with print in WPF

Odd DataGridView vertical scrolling behavior

I have a windows forms DataGridView. That I fill and update using the code below, all pretty straightforward and it is all done on the UI thread.
For some strange reason sometimes the size of the vertical scrollbar (wich I set to be only visible when needed) does not reflect the amount rows available. If I scroll all the way down, I still cannot see the very last rows. I can tell by selecting the lines below (and bringing them into view) by using the arrow down key.
What could possibly be a reason for this. Do I need some sort of BeginUdate or SuspendLayout or something? The control is embedded through interop in an MFC application.
Andy idea how to track down this problem? Is this a known bug? Google doesn't think so, it seems.
Here is the code I use.
adding or inserting a row:
int newRowIndex = insertAt;
if (insertAt < 0 || insertAt > this.dataGridView.Rows.Count)
{
newRowIndex = this.dataGridView.Rows.Add();
}
else
{
this.dataGridView.Rows.Insert(insertAt, 1);
}
removing a row:
this.dataGridView.Rows.Remove(index);
clearing:
this.dataGridView.Rows.Clear();
updating a row:
this.dataGrid[0, rowIndex].Value = someString;
this.dataGrid[1, rowIndex].Value = someBool;
this.dataGrid[2, rowIndex].Value = someInt;
I had the same problem and found that when I set the DataGridView's scrollbar property in code as opposed to the designer, it worked just fine. So I just had something along these lines:
foreach(Listitem item in list)
{
//populate grid
}
dataGridView.ScrollBars = ScrollBars.Both;
Have no idea why it worked however :)

How do I measure the dimensions of a form?

i have just designed a business information dashboard for the customer. The initial design was for a 1280x1024 screen res but it now appears that the customer has a 1024 x 768 res. This BI form is a child window of a MDI interface and as such there is a header and statusbar which means if the application is fullsized then it is occupying 1024/768 - the windows taskbar and my form has this available size minus the size of the header and statusbar of the MDI application. I can deal with this but i want to make the application customised specifically for the size of screen most frequently used which it happens is his.
Does anyone know of any places within the registry or any tools etc which can tell me the size of the window/form as it is being viewed?
Cheers
tim
I've not done any MDI stuff, but from a quick playaround I believe this might help. I put the below into a child form.
label1.Text = this.Parent.ClientRectangle.Width.ToString() + "x" + this.Parent.ClientRectangle.Height.ToString();
It seemed to return the inner size of the MDI parent. As I added more toolstrips and a status strip the height reduced.
Hope this helps.
EDIT:
Strange, this doesn't seem to bring back the parent form name (hmm a puzzle).:
label1.Text = this.Parent.Name;
EDIT 2:
but this does (note the 2nd Parent - now I'm confused):
label1.Text = this.Parent.Parent.Name;
EDIT 3:
Ok, after a couple more tests...
1. this.Parent.ClientRectangle //this seems to be the size in the MDI form - NOT including toolbars/statusstrips/menustrips etc.
2. this.Parent.Parent.ClientRectangle //Having TWO parents seems to be the main MDI size - no matter how many strips added in this seems to return the size - not including the window titlebar.
Apologies for the edits.

WPF Application Maximize Problem

How to set the Height and width of a WPF application on maximise?
Problem I face is because of variable height of the windows taskbar in different computers
Presently, I am doing it like this. Please suggest any better technique
if (this.WindowState == WindowState.Maximized)
{
this.Height = primaryScreenHeight - 10 - System.Windows.Forms.SystemInformation.SizingBorderWidth;
this.Width = primaryScreenWidth + 2 * System.Windows.Forms.SystemInformation.FrameBorderSize.Width;
}
You dont need to do this. If you use a Grid as your layout container, objects within will always expand to use up all the space. Then you can use Margins to arrange sub-panels. Using the various HorizontalAlignment values of Left,Center,Right,Stretch and VerticalAlignment values of Top, Center, Bottom, Stretch, you can make pretty much any scalable layout without having to check if the app is maximized/minimized, etc.
Is there are a particular layout you want to achieve that perhaps I can post an example for?

Expression blend like functionality in wpf

I got a canvas which has many uiElements as its children.
When i get the xaml and paste it in Expression blend it displays it well.
Now when i select a path in blend and resize it by dragging the height of it grows successfully increasing the width and the rest of the coordinates are automatically calculated.
I need to give this kind of functionality to my users for the elements on my canvas.
Just wondering if any one has any suggestions or links which can help me.
Thanks
N
You want to look at the Adorner Framework of WPF. That article gives an overview and is a good place to get started.
Here is an Adorner sample that probably does what you want.

Resources