How can I make an item inside a ToolBar fill all the remaining available space? Or, how to right-align some items, since that would give me the same effect in my case.
Note that solutions which involve nesting another container (like a Grid) inside the ToolBar don't work since that disables the special behaviour ToolBar gives to it's items (like no normal borders and look, simple outline border on hover, not receiving focus after click, etc.).
Additionally, anyone knows how to get rid of the little button that would show additional icons that overflowed from the toolbar if I had any?
I ended up using this solution:
http://karlshifflett.wordpress.com/2008/01/23/wpf-sample-series-stretch-toolbar-width-of-window/
It's not ideal, but it works. I still don't know how to get rid of the dropdown on the end though.
You can remove the button at the end by re-templating the toolbar. You can likely solve your other query this way too.
I wrote up a soluton for creating a "space filling" label that dynamically sizes to allow to you "right-align" items in a toolbar. Check it out: WPF Toolbar Items HorizontalAligment="Right"
Related
Is it possible to achieve the following visual effect in .NET MAUI/XAML:
The main concern is the outline (or lack thereof on the bottom) of the selected tab and the underline of the unselected tabs.
The goal is to be able to define an arbitrary number of Tabs for the application.
Is this possible with XAML alone?
Any help would be greatly appreciated
If I had to create custom controls I would go with the GraphicsView.
Create a custom control Tab with a canvas that draw it in function of it state, you can use StackLayout to stack them and TapGestureRecognizer to manage clicks events.
One of the main problem of a GraphicsView is that you can't attach click event to shapes you are drawing (one solution there) so you can't be really precise on the events if you don't want to manage bounding box yourself.
Or you can just use ImageButton for the tabs with a label in front for the text, it would be way easier but less flexible (tabs should all be the same sizes).
I've been tasked at work with creating a UserControl containing a ListView and ComboBox's for sorting the ListView data. Sorting with the Combobox's s the easy part; the part with which I'm having difficulty is implementing a method of scrolling. In the end, the control should have an Excel-like feel to it. However, sometimes the ListView is too tall or wide for where it is placed. Therefore, there two be two scrollbars somewhere on the control. One vertically moves of the ListView only, and the other moves both the ListView and ComboBox filters horizontally.
Please note in the image above that the ComboBox's do adjust themselves according to column width, but the code for that is not enabled at the moment.
What I've tried: In the control, the filter boxes are in their own panel, and the ListView has had its own panel at times. I've tried using various combinations of the HScroll/VScroll and HorizontalScroll/VerticalScroll properties and the native function ShowScrollBar() for all the controls, but nothing has worked. The only way I've gotten scrollbars to appear is by settings AutoScroll (Scrollable for the ListView) to true. Of course, the scroll bars come in pairs and work only on the same control. I also attempted to programmatically move the scroll bars, but I haven't been able to accomplish that, either.
I've got to be doing something wrong, but I'm not sure what it is. Any help is appreciated!
I think I'd go for a different solution.
If you put the ComboBoxes in a AutoSrcoll panel with the same Anchors as the ListView you would give your users the freedom to scroll the two independently.
Yes, a ScrollBar would appear and take space but I would still happily sell that as a feature, not a bug ;-)
As for handling the Scroll event of a ListView: It is hidden and you'll have to subclass it to get access to it. See here
Finishing up a register form in a C# application and I noticed with the panel if I enable AutoScroll and then have a textbox that is below the scroll and click on it it jumps all the way back up to the top. Is there a way to fix this with some code or is it a propriety?
It's a little difficult for me to explain it in words, so here's a short video that shows the behavior.
I have had the same problem. I fixed it with this code in my panel:
protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosition;
}
I had this exact problem. I had to remove the docking from my panels on the form and this fixed the problem.
Since apparently no one has seen this behavior before and could provide a quick answer, I opened up Visual Studio to try and reproduce what you describe.
I created a new WinForms project with a GroupBox containing a Panel whose AutoScroll property is set to "True". Then, I added two new GroupBox controls inside of the Panel, each containing two TextBox controls. The first embedded GroupBox is at the top of the form, entirely visible at startup; the second embedded GroupBox is at the bottom where it must be scrolled into view. This is equivalent to the design/layout that you have as best I can tell from your description and video.
However, when I run the project, scroll down to the second embedded GroupBox and select one of the TextBox controls that it contains, it performs exactly as expected. The TextBox control that I clicked on gets the focus, without scrolling the entire panel back up to the top. I can't seem to reproduce what you're seeing. If you could either tell me what I've done wrong in designing my test sample or post the smallest sample project needed to recreate the behavior you're experiencing, I might be able to help.
Otherwise, here are a few suggestions of things to investigate:
The tab order of the objects on your form. This really shouldn't be causing the behavior described because clicking on a control should set the focus to that control, regardless of its position in the tab order, and jumbling up the tab order multiple times in my sample project still doesn't appear to have the same effect. But I suppose it's worth a try anyway. In Design Mode, go to your "View" menu, and click "Tab Order". All of the controls that you can set the tab order for will have a little colored box at their top-left corner, indicating their tab order in each container. To set the tab order, click once on each of the controls in the natural order you want them to be focused.
Scour your code for any <Control>.Focus or <Control.Select> statements. Make sure that you don't have any validation code that's altering the tab order in any way during run-time. This could be causing focus to jump back to a control located near the top of your Panel, forcing it to auto-scroll to the new location.
Try to reproduce the behavior in a brand new, clean project. Ideally, create a new project in Visual Studio and lay out the controls the exact same way you have them in the project with which you're experiencing difficulties. This is the same thing I did, partly because I don't have your particular project to work with, and also because this is the best way to troubleshoot particularly tricky behavior. It's more likely there is some quirk to your design or source code that's causing this behavior, rather than some kind of bug in the controls themselves. But either way, this will let you know exactly where the problem is occurring, which will get you that much closer to a solution.
You can use TableLayoutPanel" instead of "Panel" to avoid scrollbar change its position.
For some reason the labels for "Date From" and "Date To" are rendering strangely on their bottom edges. See how the datepickers are not rendered correctly because of this.
Anyone know why this is occurring? It only occurs when I start the app from the exectuable. It doesn't happen in the IDE.
It looks like the bounds of the Label controls are spilling over into the DateTimePicker controls. Even when a WinForms control has a transparent background, it is not guaranteed to play nice with other controls in the same container. Try reducing the margins/padding on the labels or select both DateTimePicker controls and use the "bring to front" option.
They have a backcolor that matches the form's backcolor.
There are multiple ways to solve this:
Right-click on the label and choose "Send to Back"
Right-click on the other control and choose "Bring to Front"
Make sure the label's AutoSize property is set to true and move it up a little until it doesn't show
Make sure the label's Padding property is 0, 0, 0, 0 (zero for each subproperty)
It's frighteningly easy in VS to accidentally change the size and location of controls when manipulating them with the mouse. You may just have to move/re-size them so they don't overlap. Try moving with the arrow keys or explicitly giving them numeric position and size values.
As mickeyf notes, it's very easy to accidentally move or resize a control.
To reduce the likelihood of this happening, VS allows you to lock controls. If you right click anywhere on the form, and select "Lock Controls", this will lock every control on the form. I always found this to be too draconian, and rarely used it.
But what I somehow missed until very recently, each control has a "Locked" property that can be set individually. I find this much more convenient - you just lock the controls that tend to be problematic.
For example, I have several forms that have a toolbar at the top, and another control that exactly fills the rest of the form. It's very easy to accidentally bump this control by a pixel or so, and not realize it. Now I just lock those controls, which is way more convenient than locking everything.
I was wondering... I have a WinForms System.Windows.Forms.ListView with a bunch of ListViewItems that I'm drawing using the View.List style. Each ListViewItem has a "SmallIcon" that I fetch from the ListView's SmallImageList.
My problem is that the icons are showing too close to the border on the left. I've tried to change the bounds and the ListViewItem's Position property to no avail.
Is there anyway to have some kind of offset to ListViewItems?
The Win32 listview control doesn't have any setting to increase the space between the icon and the label (in any view, not just List). Setting ListViewItem.Position does nothing when the ListView is in List view.
A low-tech solution would be to simply prefix every ListViewItem's Text value with a single space. Slightly ugly, but oh so easy to do.
If you really want to have pixel level control, you will have to owner draw it. As always, if you are doing anything with a .NET ListView, ObjectListView makes owner drawing your items trivial.
As mentioned already, prefixing the text of all your items with a space is a super simple way to add padding. This has a pretty significant drawback, however. Once you do this, you lose the ability to find items in the ListView by simply starting to type their name while the ListView has focus.
Try adding white space to the left of your small images.
If you're using 16x16 images change to 24x16 for example by adding 8 white (or ListView Background color) pixels to the left.
If you are in ListView View LargeIcons then you can postion the text using item.position
A screenshot would be nice for an example to see exactly what you're after.
Funny thing... the Windows Explorer uses the ListView to display files and folders. i usually run my view in Report or Detail mode. i just switched it to List view mode and see the exact problem that you're describing! Yikes. Might be a bug with the Win32 object and that particular view type!
A quick workaround might be to use a Report style for the ListView with a single column or perhaps implement something yourself. The FlowLayoutPanel in .Net would work very nicely as a starting point for a custom list view.
As you are using the View.List style, I suspect you'll either need to implement some custom drawing or consider padding your images. You could also look at overriding the ListView control and manipulating it's bounds by overriding SetBoundsCore or SetClientSizeCore (or similar).
However, if the ListView were set-up for View.Details view, this could be done using the ListViewItem.IndentCount property:
The IndentCount property can be used
only when the View property of the
containing ListView is set to Details,
and the SmallImageList property of the
ListView is set. Source:MSDN
If you set the StateImageList property you can add a space of 16 px before the icons. I think you can adjust this additional space by loading an image with matching width as first entry into the StateImageList. But I have not tested this.
This thread discusses the opposite problem.