how to disable form resizing using c# - winforms

How to disable form resizing using c# ?
I just want to avoid resizing my form by user.
I tried changing FormBorderStyle But it doesn't work
Thanks!

Take a look at the FormBorderStyle property
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
You may also want to remove the minimize and maximize buttons:
form1.MaximizeBox = false;
form1.MinimizeBox = false;

Related

WPF popup closing before treeview selection

I'm working on a project with a treeview inside a popup. I need to have it where the popup remains open until a selection is made on the treeview. At first I tried controlling this with selectedItemChanged on the treeview, then MouseLeave, but if you overshoot the popup by just a pixel, it closes without you being able to make a selection on the treeview.
I'm looking to do something such as"
if (dirTree.SelectedItem = "")
{
popup1.IsOpen = true;
}
popup1.IsOpen = false;
but that gives me "Possible unintended reference comparison; to get a value comparison, cas t the left hand side to type 'string'."
I've been searching using "treeview any selected" "treeview SelectedItem", etc. Admittedly it may just be a simple syntax issue because I'm new to C# and WPF.
Do your check to make sure its's not null and then you can do dirTree.SelectedItem.Equals("") or cast to the expected type.

How to hide the Group Tree of a Crystal Report in WPF?

I'm using VS2010 and Crystal reports 13.
Is there any way to collapse/hide the group tree box that appears on the left hand side of my generated report? I saw a couple of proposed solutions but none seem to work for me.
Thanks in advance.
There also is a property on report viewer you can set as follows:
yourViewer.ToggleSidePanel = Constants.SidePanelKind.None;
I think this is a bit safer in case the Crystal Reports team decides to rename that button.
I finally found a solution that works, by manually finding the side panel and then hiding it:
var sidepanel = crystalReportsViewer1.FindName("btnToggleSidePanel") as ToggleButton;
if (sidepanel != null) {
crystalReportsViewer1.ViewChange += (x, y) => sidepanel.IsChecked = false;
}
adding this namespace:
using System.Windows.Controls.Primitives;
The problem was that the WPF ReportViewer is slightly diferent to the Win Forms one, some properties (such as ToolPanelView and ShowGroupTreeButton) have been removed, I tried many different things but the above was the only that did the trick.
You can change it from the designer by changing the 'ToolPanelView' to 'None' and hide the button by changing 'ShowGroupTreeButton' to 'false'. Previous versions had a method to explicitly hide the group tree but I believe it's been deprecated in the version you are using. To change the properties in code behind:
crystalreportviewer.ToolPanelView = TooPanelViewType.None;
crystalreportviewer.ShowGroupTreeButton = false;
there is a property DisplayGroupTree . and you can avoid the free space by using this code
CrystalReportViewer1.DisplayGroupTree = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
Use the command to hide the panel.
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
I ran into the same issue as Crystal Report changes the convention. In older version of the Crystal report would hide the button and not show the panel on the left hand side.
CrystalReportViewer1.ShowGroupTreeButton = False
<Viewer:CrystalReportsViewer ToggleSidePanel="None"/>
Use the following properties in your webpage:
- ToolPanelView="None"
- HasToggleGroupTreeButton="false"
<CR:CrystalReportViewer ID="CRViewer" runat="server" HasCrystalLogo="False" ToolPanelView="None" HasToggleGroupTreeButton="false" BestFitPage="True" AutoDataBind="true" />
Group tree panel and its toggle will be hidden. It works well in my environment - ASP.Net 4.0, Crystal Report version 13.0.13
For asp.net
CrystalReportViewer1.ToolPanelView=CrystalDecisions.Web.ToolPanelViewType.None;

WPF How to add and perform events on those controls generated during Runtime

For example, I have an empty tabControl in my Windows during the compile time, and I have an undetermined amount of images need to be added onto the tabControl, so I used loop + tabControl.Children.Add("image1 to x") to add those images... but after that during runtime, I want to perform events on those image controls, such as dragging the image from the tabControl to another Panel. Is it possible to do so? If it's possible, how?
I don't know if I understood what exactly you want, but if you want to add an event handler for a control in runtime, you can do that like the following sample:
Image i = new Image();
i.Click += (sender,e) => { [write here your code] };
for drag and drop, you can see the thumb control, It might help you

Selecting an item in a ListView control ( winforms ) while not having the focus

I am trying to mimic the functionality of the address book in Outlook
So basically a user starts typing in some text in an edit control and a matching ListView Item is selected
private void txtSearchText_TextChanged(object sender, EventArgs e)
{
ListViewItem lvi =
this.listViewContacts.FindItemWithText(this.txtSearchText.Text,true, 0);
if (lvi != null)
{
listViewContacts.Items[lvi.Index].Selected = true;
listViewContacts.Select();
}
}
The problem with this is once the listview item gets selected the user cant keep typing into the text Box. Basically I want a way to highlight an item in the listview while still keeping the focus on the edit control
This is WINFORMS 2.0
Manually setting ListViewItem.BackColor is not good a solution, especially if you want the item to get the selected state, because it only works on unselected items. So you had to take care of several situations to make it look right in all cases (really select the item as soon as the ListView gets focus, undo the color changes, and so on...)
It seems the only good way is to use Ownerdraw or an extended ListView like ObjectListView.
I was looking for the same and I still hope for a better/smarter solution, or at least a nice and short Ownerdraw implementation.
Update
I found a better solution for me: I now use a DataGridView for the same purpose (which also has other advantages in my case, since the data comes from a db anyway, but it would also work without db). There the selection bar doesn't change color when loosing focus. You can try a few properties to make it look like a ListView:
dgv.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None;
dgv.ColumnHeadersVisible = false;
dgv.MultiSelect = false;
dgv.ReadOnly = true;
dgv.RowHeadersVisible = false;
dgv.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
dgv.StandardTab = true;
ok never mind it's doable by just manipulating the background colour of the selected item

Showing a tooltip inside a datagrid

I'm trying to show a windows forms tooltip inside a datagrid to highlight an error. The problem I have is that everytime I call tooltip.Show("You have an error", datagrid, 0, 0), The tooltip is confined within the datagrids boundaries and doesn't go outside, which ultimately means the tooltip itself covers up the actual row where the error occurs.
I thought about tooltip.Show("You have an error", Form1, ?, ?) but I don't see an easy way to compute the offset of the datagrid on the form. Since all controls are docked, depending on how the user resizes the form, the location will change.
There is a caveat, the datagrid itself is not a Forms.DataGrid, instead it is an Infragistics UltraGrid which may do funny things itself, which are outside of my ability to alter.
It turns out that it's easy enough to get the location for the Show command from the UltraGrid by querying the UIElement associated with it. Here's what I'm doing:
private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
{
if (!DataFormat.CanEdit(e.Cell.Row.ListObject, e.Cell.Column.PropertyDescriptor))
{
var tip = new System.Windows.Forms.ToolTip();
tip.BackColor = Color.Orange;
tip.Show("unable to edit", this, e.Cell.GetUIElement().Rect.Left, e.Cell.GetUIElement().Rect.Top, 500);
e.Cancel = true;
}
}
Have you looked at these:
HOWTO:Create Advanced ToolTips For The WinGrid
BeforeDisplayDataErrorTooltip Event

Resources