Search Results

Search found 2806 results on 113 pages for 'winforms'.

Page 59/113 | < Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >

  • Unable to Calculate Position within Owner-Draw Text

    - by Jonathan Wood
    I'm trying to use Visual Studio 2012 to create a Windows Forms application that can place the caret at the current position within a owner-drawn string. However, I've been unable to find a way to accurately calculate that position. I've done this successfully before in C++. I've now tried numerous methods in C#. Originally, I tried using .NET classes to determine the correct position, but then I tried accessing the Windows API directly. In some cases, I came close, but after some time I still cannot place the caret accurately. I've created a small test program and posted key parts below. I've also posted the entire project here. The exact font used is not important to me; however, my application assumes a mono-spaced font. Any help is appreciated. Form1.cs This is my main form. public partial class Form1 : Form { private string TestString; private int AveCharWidth; private int Position; public Form1() { InitializeComponent(); TestString = "123456789012345678901234567890123456789012345678901234567890"; AveCharWidth = GetFontWidth(); Position = 0; } private void Form1_Load(object sender, EventArgs e) { Font = new Font(FontFamily.GenericMonospace, 12, FontStyle.Regular, GraphicsUnit.Pixel); } protected override void OnGotFocus(EventArgs e) { Windows.CreateCaret(Handle, (IntPtr)0, 2, (int)Font.Height); Windows.ShowCaret(Handle); UpdateCaretPosition(); base.OnGotFocus(e); } protected void UpdateCaretPosition() { Windows.SetCaretPos(Padding.Left + (Position * AveCharWidth), Padding.Top); } protected override void OnLostFocus(EventArgs e) { Windows.HideCaret(Handle); Windows.DestroyCaret(); base.OnLostFocus(e); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawString(TestString, Font, SystemBrushes.WindowText, new PointF(Padding.Left, Padding.Top)); } protected override bool IsInputKey(Keys keyData) { switch (keyData) { case Keys.Right: case Keys.Left: return true; } return base.IsInputKey(keyData); } protected override void OnKeyDown(KeyEventArgs e) { switch (e.KeyCode) { case Keys.Left: Position = Math.Max(Position - 1, 0); UpdateCaretPosition(); break; case Keys.Right: Position = Math.Min(Position + 1, TestString.Length); UpdateCaretPosition(); break; } base.OnKeyDown(e); } protected int GetFontWidth() { int AverageCharWidth = 0; using (var graphics = this.CreateGraphics()) { try { Windows.TEXTMETRIC tm; var hdc = graphics.GetHdc(); IntPtr hFont = this.Font.ToHfont(); IntPtr hOldFont = Windows.SelectObject(hdc, hFont); var a = Windows.GetTextMetrics(hdc, out tm); var b = Windows.SelectObject(hdc, hOldFont); var c = Windows.DeleteObject(hFont); AverageCharWidth = tm.tmAveCharWidth; } catch { } finally { graphics.ReleaseHdc(); } } return AverageCharWidth; } } Windows.cs Here are my Windows API declarations. public static class Windows { [Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct TEXTMETRIC { public int tmHeight; public int tmAscent; public int tmDescent; public int tmInternalLeading; public int tmExternalLeading; public int tmAveCharWidth; public int tmMaxCharWidth; public int tmWeight; public int tmOverhang; public int tmDigitizedAspectX; public int tmDigitizedAspectY; public short tmFirstChar; public short tmLastChar; public short tmDefaultChar; public short tmBreakChar; public byte tmItalic; public byte tmUnderlined; public byte tmStruckOut; public byte tmPitchAndFamily; public byte tmCharSet; } [DllImport("user32.dll")] public static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight); [DllImport("User32.dll")] public static extern bool SetCaretPos(int x, int y); [DllImport("User32.dll")] public static extern bool DestroyCaret(); [DllImport("User32.dll")] public static extern bool ShowCaret(IntPtr hWnd); [DllImport("User32.dll")] public static extern bool HideCaret(IntPtr hWnd); [DllImport("gdi32.dll", CharSet = CharSet.Auto)] public static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC lptm); [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); [DllImport("GDI32.dll")] public static extern bool DeleteObject(IntPtr hObject); }

    Read the article

  • How do I detect a change of tab page in TabControl prior to SelectedIndexChanged event?

    - by JYelton
    I currently determine what page of a tabcontrol was clicked on via the SelectedIndexChanged event. I would like to detect before the selected index actually changes, for validation purposes. For example, a user clicks a tab page other than the one they are viewing. A dialog is presented if form data is unsaved and asks if it's ok to proceed. If the user clicks no, I'd like to remain on the current tab. Currently I have to remember the previous tab page and switch back to it after an answer of 'no.' I considered MouseDown (and the assorted calculation logic), but I doubt that's the best way. (This is in .NET C# 3.5)

    Read the article

  • ComboBox SelectedItem vs SelectedValue

    - by Anna Lear
    The following code works as you’d expect — MyProperty on the model is updated when the user picks a new item in the dropdown. comboBox1.DataBindings.Add("SelectedValue", myModel, "MyProperty", true, DataSourceUpdateMode.OnPropertyChanged); The following, however, doesn’t work the same way and the model update isn’t triggered until the input focus moves to another control on the form: comboBox1.DataBindings.Add("SelectedItem", myModel, "MyProperty", true, DataSourceUpdateMode.OnPropertyChanged); Does anybody know why? I don’t even know where to start investigating the cause. Pointers in the right direction to start the investigation or an outright explanation would be equally appreciated. Thanks.

    Read the article

  • Business Objects Web Intelligence-style reporting in a Winform app. Is this possible?

    - by George
    I have a WinForm app that displays results in a Gridview control. If a user right mouse clicks on a row, he can then, from a popup menu, select a command to perform on the row much like windows File Explorer. But now I want to be able to give the user the ability to construct a filter so that he can control which rows are displayed in the grid w/o effecting the functionality of the application. I would also like the user to be able to select the columns/fields that he sees in the grid. For the basis of this question, let's assume that the data displayed in grid comes from a single table. business Objects' Web Intelligence and Desktop Intelligence applications give me very flexible and powerful reporting capabilities, but I want to integrate this capability into my WinForm application. Does Business Objects, or maybe Crystal Reports provide this sort of functionality? I can construct my own query builder but I'd rather not reinvent sliced bread.

    Read the article

  • How to roll back changes in gridview in case of incorrect input

    - by Mustafa A. Jabbar
    Hi, I have a DataGridView that is bound to a list of object. It has some columns that the user can edit. There are certain inputs that are not allowed for a row as a whole. How can I roll back if the user enters invalid inputs in some cell. I tried using the RowValidating event handler but it was not called after cell value has been changed. Even when I implemet CellValueChanged, I still cannot roll back the changes. Any idea how to accomplish this

    Read the article

  • Move controls when Drag and drop on panel in C#

    - by C. Karunarathne
    I want to drag controls on panel and when dragging I want to move the control and get its location to drop on to panel.I have tried out mouseUp,mouseDown,MouseMove events of control.But that is not what I am looking for.I want to fire DragDrop event on panel and move control.Can I do this?If you can give me an idea it will be great.Thank you

    Read the article

  • How to Form.GetChildSAtPoint?

    - by serhio
    I would like to obtain the list of controls under a given point. There is a method on System.Windows.Form to obtain a control under a point(GetChildAtPoint) but not point(GetChildsAtPoint). Is there something similar for the list of controls (if borders intersect one other): I need this because I select the objects when user clicks on the panel(I use Microsoft.VisualBasic.PowerPacks.RectangleShape as label bellow). In case if labels are superposed, user should be asked what object to select.

    Read the article

  • Loop Stored Procedure in VB.Net (win form)

    - by Mo
    Hello, I am trying to run a for loop for a backup system and inside that i want to run a SP that will loop. Below is the code that does not work for me.. Any ideas please? Dim TotalTables As Integer Dim i As Integer TotalTables = 10 For i = 1 To TotalTables objDL.BackupTables(220, i, 001) ' (This is a method from the DL and the 3 parameters are integars) Next I tried the SP and it works perfectly in SQLServer

    Read the article

  • hidden forms and thr handles

    - by shraddha
    i am hiding the form using SetVisibleCore to false, but now i cant get the handle of this form in other application which i am retrieving using EnumWindow its giving me exception "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." an ACCESS VIOLATION EXCEPTION. so i am searching on 2 ways 1. find out the other way to get handle here we cant use FindWindow cause its not returning any handle 2. find a another way to hide the form but this should be done before loading of the form so,,,plz help me if anybody can

    Read the article

  • Custom DataGridView column sort based on Value not Formatted value

    - by Dan Neely
    I have a custom DGV cell I'm using to display the contents of MyType objects. To control how they're being formatted I'm overriding the GetFormattedValue() and FormattedvalueType methods of DataGridViewTextBoxCell because in this case I don't want to use the default ToString() method. The problem is that when I do this the DGV is sorting the column by the string in FormattedValue instead of by Value. I'm not seeing a method I can override to change the sort behavior of the column. While I know I can, I don't want to have to write custom Sort mthods for the DGVs themselves because I'm using this in multiple DGV's.

    Read the article

  • how to implement undo operation in datagridview

    - by ush
    Hi, I have created one application in c#.net.Using this application we can update datagridview,now i need to implement undo in it plz give me some ideas. private void button29_Click(object sender, EventArgs e) { Datatable dt; dt.RejectChanges(); } using above code i can do undo before updating. but i need a undo feature as in word plz suggest me thanks in advance

    Read the article

  • CSharp Compiler and Windows.Forms

    - by j-t-s
    Hi All I've just created a little app that programmatically compiles code using the C# Compiler, and it works brilliantly. But, one thing that I need it to do is compile Windows.Forms code. Like, I can create a console app with it, but I can't create a GUI-based form. Here's the link that got me started: http://support.microsoft.com/kb/304655 Can somebody please help? Thank you :)

    Read the article

  • Databinding in windows forms on an object graph with possible null properties?

    - by Fredrik
    If I have an object graph like this: class Company { public Address MainAddress {...} } class Address { public string City { ... } } Company c = new Company(); c.MainAddress = new Address(); c.MainAddress.City = "Stockholm"; and databind to a control using: textBox1.DataBinding.Add( "Text", c, "MainAddress.City" ); Everything is fine, but If I bind to: Company c2 = new Company(); c2 using the same syntax it crashes since the MainAddress property is null. I wonder if there is a custom Binding class that can set up listeners for all the possible paths here and bind to the actual object dynamically when/if I sometime later in the application set the MainAddress property.

    Read the article

  • WPF/Winform Time Range Selector

    - by wonea
    Hello, I'm looking for a decent WPF or Winform time range selector, much like a home central heating system, where a time range is selectable. http://lhill.com.au/l%20hill%20web%20page%20pictures/time%20clock%202.jpg Is there any GUI libraries or examples available to fulfill this need?

    Read the article

  • Hide TabControl buttons to manage stacked Panel controls

    - by Luca
    I need to handle multiple panels, containing variuous data masks. Each panel shall be visible using a TreeView control. At this time, I handle the panels visibility manually, by making the selected one visible and bring it on top. Actually this is not much confortable, especially in the UI designer, since when I add a brand new panel I have to resize every panel and then design it... A good solution would be using a TabControl, and each panel is contained in a TabPage. But I cannot find any way to hide the TabControl buttons, since I already have a TreeView for selecting items. Another solution would be an ipotethic "StackPanelControl", where the Panels are arranged using a stack, but I couldn't find it anywhere. What's the best solution to handle this kind of UI?

    Read the article

  • C# WebClient - View source question

    - by Jim
    I'm using a C# WebClient to post login details to a page and read the all the results. The page I am trying to load includes flash (which, in the browser, translates into HTML). I'm guessing it's flash to avoid being picked up by search engines??? The flash I am interested in is just text (not an image/video) etc and when I "View Selection Source" in firefox I do actually see the text, within HTML, that I want to see. (Interestingly when I view the source for the whole page I do not see the text, within HTML, that I want to see. Could this be related?) Currently after I have posted my login details, and loaded the HTML back, I see the page which does NOT show the flash HTML (as if I had viewed source for the whole page). Thanks in advance, Jim PS: I should point out that the POST is actually working, my log in is successful.

    Read the article

  • using Label control to create looping marquee text in c# winform

    - by hanmyint
    I have been create Marquee text using Label control her is sample code public partial class FrmMarqueeText : Form { private int xPos = 0, YPos = 0; public FrmMarqueeText() { InitializeComponent(); } private void FrmMarqueeText_Load(object sender, EventArgs e) { lblText.Text = "Hello this is marquee text"; xPos = lblText.Location.X; YPos = lblText.Location.Y; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (xPos == 0) { this.lblText.Location = new System.Drawing.Point(this.Width, YPos); xPos = this.Width; } else { this.lblText.Location = new System.Drawing.Point(xPos, YPos); xPos -= 2; } } but when the first time was finished, it didn't continues work .Please help me!

    Read the article

  • Using VirtualMode on a DataGridView when the number of rows/columns isn't known

    - by Nathan Baulch
    I need to display an unknown length sequence of dictionaries with unknown keys efficiently in a data grid. This sequence is the result of a potentially slow LINQ query that could contain any number of results. At first I thought that VirtualMode on DataGridView was what I was looking for but it appears that the number of rows and columns must be known upfront. I tried adding a single row and column then adding more as needed from the CellValueNeeded event but this doesn't work. Is this even possible with VirtualMode? Or do I need to estimate how many rows are visible on the screen and manually build up the rows/columns? And if so, how do I ensure that a vertical scrollbar is present and react appropriately when a user uses it?

    Read the article

  • Is there a way to allow a property of a user control to be modified only during design time?

    - by Dan
    I've looked into the DesignOnly attribute, but that doesn't seem to accomplish what I want*. Basically, I'm looking for some way to indicate that some property of a user control (let's say Text) can be modified during design time -- i.e., from the Windows Forms designer in VS (or presumably from any GUI designer that can be used to modify a Windows Forms GUI) -- but not during run time. Once the application is running, the property should effectively be readonly. Is this possible? * When I add the DesignOnly attribute to a property, the value I select for that property from design mode doesn't seem to stick; the property just ends up being whatever I have it set to by default in code.

    Read the article

  • How can I bind a custom property of a windows form to a second property?

    - by jeroko
    I want to bind a custom property of a windows form to a second property, so when I update the former the latter gets the same value. This is the simplest example of what I'm trying to do: public partial class Form2 : Form { public string MyTargetProperty { get; set; } public string OtherProperty { get; set; } public Form2() { InitializeComponent(); this.DataBindings.Add("MyTargetProperty", this, "OtherProperty"); } private void button1_Click(object sender, EventArgs e) { MyTargetProperty = "test"; Console.WriteLine("OtherProperty " + OtherProperty); } } When I click button1 I should be able to see that 'OtherProperty' has the same value as 'MyTargetProperty'. Am I doing something wrong? Do I miss something?

    Read the article

  • Better way to kill a Form after the FormClosing event is overridden to hide rather than close?

    - by Paul Sasik
    I have a simple Windows Form that hosts property controls at runtime. To keep the window and its contents alive rather than killing it by handling the FormClosing event, cancel the event and simply hide the form. That's fine but at close of the application I need to actually close the window. I implemented the below but it feels kludgey. Is there a simpler, more clever way to handle this situation? (The form's controller calls KillForm explicitly after it receives a closing event from the main window.) Friend Class HostForm Private _hideInsteadOfClosing As Boolean = True Private Sub HostForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) _ Handles Me.FormClosing If _hideInsteadOfClosing Then Me.Hide() e.Cancel = True End If End Sub Public Sub KillForm() _hideInsteadOfClosing = False Me.Close() End Sub End Class

    Read the article

< Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >