Centering an application when starting?
Does anyone know how to center an application on the desktop when starting
rather than rely on the default location? Tag: Displaying version info onto a label Tag: 61927
[ANN]unofficial Extensibility Application Block
Hi Folks.
Look here for the full details:
http://weblogs.asp.net/rosherove/posts/39484.aspx
and here for the download:
http://workspaces.gotdotnet.com/eap
in a few sentences:
This block allows you to incorporate plugins into your application with
ease. It also allows to easily create plugins for your application if it
uses this framework.
intro:
Extensibility Application Block
overview:
One of the demands from a successful application is the abilityto easily
adept to the needs of its users if and when they change (and they do). Many
times, the required changed, or extra features that need to be added
require not only pure development work, but also re-compilation of some or
all of the application binaries (this discussion does not include web
applications, only winform applications).
To avoid having to go through this sometimes painful process just to add a
simple feature, or fix a simple bug, a new need has grown - to allow
extending an existing application without the need to recompile it or even
without the help of the original developer. This is how what we know today
as Add-ins and plugins were born.
When we moved into the world of .Net, we still have the ability to write
applications that can be extended by others. However, there is no clear
path, a common way, to design and implement such abilities into .Net
applications. If you were to go today and try to build an extensible
application, you'll be faced with a myriad of articles and HOW-TOs, each
explaining the story a little bit differently than it's predecessor.
This Application block was created so that we can start and retain a common
ground for how such abilities should be built. So that it can be both easy
to understand and powerful enough as to be used by the most demanding
applications.
The solution I present here is based on my experience writing extensible
applications in .Net and on all the things I learned while trying to figure
out the best way to achieve specific abilities while trying to maintain a
generic approach.
How does it work?
There are 3 basic principles that need to be implemented in order for an
application to have plugins:
1. The application needs a way to recognize and communicate with the
plugins
2. The Plugins need a way to talk (or sometimes control) the application in
which they are hosted
3. The plugins need to be recognized and loaded at runtime into the host
application
1. The application needs a way to recognize and communicate with the
plugins
This application block solves this problem by providing a common interface
that all plugins must implement:IPlugin.
The principle is actually very simple:
Let's say I have a text editing application to which I would like people to
be able to add plugins.
These plugins should be able to talk to the application in which they
reside, AND the application should be able to talk to them.
However, since the application does not know in advance what plugins may be
available (some of them may only be created in the future!) the application
cannot have a direct reference on any specific DLL or class. It needs to
support ANY CLASS but it needs to be able to talk to it on pre-known terms.
This paradox is solved by the using a COMMON INTERFACE that both the plug
in and the application know. This interface is declared in a separate
assembly and both the plug in and the application have a reference to that
assembly.
This interface is what our application will use to communicate with the
plug in. Any plug in that will want to attach itself to the app will have
to implement this interface or otherwise we won't even try to load it. This
interface is called (in this application block) IPlugin.
2. The Plugins need a way to talk (or sometimes control) the application in
which they are hosted
This application block solves this problem by providing a base class called
AppContext. To the Plugins, AppContext is their one and only link to the
outside world. Anything they need to do, anything they need to know, they
do it through this class. The host application will hold a class derived
from AppContext which has specific methods and properties which should be
shared with the plugins. the IPlugin interface contains an Init Method
which passes an AppContext instance into the plug in, allowing it to hold a
reference to it and using it for what it needs. For example, For an Editor
application, We can have an EditorContext class which exposes events such
as TextChanged and properties such as SelectedText and so on. The plugins
can use these properties to manipulate their outside environment . It all
depends on how much the developer decides to expose to the plugins using
the AppContext class. The AppContext class is also the class that will load
and unload the plugins when the application starts and finishes, but for
that it uses yet another class from the application block - the
PluginProvider classes which I'll now discuss in the next paragraph.
3. The plugins need to be recognized and loaded at runtime into the host
application
There are many ways in which one can organize and recognize the plugins
that their application needs to load. Some prefer to dynamically search all
the DLLs in the app directory and find classes that implement the IPlugin
Interface. Some prefer to list the required plugins and their type inside
the application config file. Some might have a whole different way of doing
this which no one has ever thought of before. This application block is
built to support whatever method you choose to load your plugins, and it
also provides a couple of implementations right off the bat so you can get
up and running in no time with your new application.
In the extensibility block there are special objects for which the only
purpose in life if to find and load plugins. These are called Plugin
Providers. Each plug in provider must implement the IPluginProvider
interface. There are several providers already build for you. These include
the XmlFilePluginProvider, SectionHandlerPluginProvider and
DynamicFindPluginProvider. Each of these implements searching for plugins
in a totally different way, but because they all support the same
interface, they all return a collection of IPlugin object when they are
done allowing you to simply choose the method in which to search.
Don't find anything you like in there? Feel like you need an extra feature?
Simple implement the IPluginProvider interface in your own class and you're
free to go.
--
Roy Osherove
weblog: http://www.iserializable.com Tag: Displaying version info onto a label Tag: 61925
Unwanted Focus in TabControl
Hi,
When I'm using the SelectedIndex property to
programmatically change the current TabPage of a
TabControl (or controlling it by DataBinding), the
corresponding TabPage "steals" Focus. Does anybody know a
simple way to avoid this?
Thank you in advance!
Per Tag: Displaying version info onto a label Tag: 61923
No touch deployment and XP Themes
Hi.
How do I adopt XP-theme together with no touch deployment?
I am using no touch deployment of a windows application (framework
1.1).
The problem is when deploying the application through no touch the
visual style does not adopt XP-themes.
I am using...
Application.EnableVisualStyles();
Application.DoEvents();
... but i do not seems to work.
I have also tried to use a Manifest file, but i do not think it is
sent to the client computer. Maybe I am doing something wrong!?!
Can anybody please help!
Thanks in advanced. Tag: Displaying version info onto a label Tag: 61919
Focus form after use popup menu in notifyicon
Hello,
I have form with notifyIcon and popup menu for notifyIcon. I modified
Close event - I hide form instead close. When I clik to icon in
systray, form shows. But when I selected item from popup menu over
notifyIcon, form shows too - but I don't show it, only run any code.
How do I it?
Ehh, sorry for my english :/
There is source code (I wrote it in C#Builder Personal):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Project1
{
/// <summary>
/// Summary description for WinForm.
/// </summary>
public class WinForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private bool closeFromMenu;
private System.Windows.Forms.MenuItem menuItem2;
public WinForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
closeFromMenu = false;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(WinForm));
this.notifyIcon1 = new
System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon =
((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
this.notifyIcon1.Click += new
System.EventHandler(this.notifyIcon1_Click);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "Exit";
this.menuItem1.Click += new
System.EventHandler(this.menuItem1_Click);
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Click";
this.menuItem2.Click += new
System.EventHandler(this.menuItem2_Click);
//
// WinForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(264, 237);
this.Name = "WinForm";
this.Text = "WinForm";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.WinForm_Closing);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new WinForm());
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
closeFromMenu = true;
this.Close();
}
private void WinForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (!closeFromMenu)
{
this.Visible = false;
e.Cancel = true;
}
}
private void notifyIcon1_Click(object sender, System.EventArgs e)
{
if (!this.Visible)
{
this.Visible = true;
} else
{
this.Activate();
}
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
// any code
}
}
} Tag: Displaying version info onto a label Tag: 61911
html control
I asked this a few days ago but it appears I didnt word it correctly.
Is there any way to place a html control onto a windows form in .net such
that the javascript on the html displayed within the html can access
properties and methods of the application via the external object in JS? Tag: Displaying version info onto a label Tag: 61902
Textbox-level validation
Folks,
I have a C# WinForms app, and I am doing some validation of text boxes
and their contents.
So far, I've used the TextBox1_Leave event - if the focus goes away
from the textbox, I check for certain conditions (not empty, valid
entry etc.).
This works okay so far - but in some cases, I'd like to skip that
validation, e.g. when the user clicks on the "Cancel" button.
But how can I "foresee" that the user has clicked the Cancel button,
inside my TextBox1_Leave event?? In Delphi, we used to be able to
inspect a property "ActiveControl" which was set to the button that
had been clicked - based on that info, I was able to determine whether
or not I wanted to apply my validation.
I don't seem to find anything similar in C# / .NET - I do have an
"ActiveControl" property, but that is still set to my text box, as
long as I'm still on it.....
Any way to achieve what I'm trying to do without major kludges??
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch Tag: Displaying version info onto a label Tag: 61901
abstract form
why i cannot code a form as abstract in order for other form to inherite it
in C#?
thz Tag: Displaying version info onto a label Tag: 61892
Scope of form variables...
This may sound like a dumb question, but I am hoping someone might comment
on it....
Consider the following method (assuming that Form1 is a class derived from
System.Windows.Forms.Form) :
private void MyMethod()
{
int i = 1;
Form1 myForm = new Form1();
myForm.Show();
}
Both of the variables, i and myForm, are local variables that should go out
of scope when the method is finished executing. But the myForm variable
continues to live on. Is this correct? Why is the scope of form variables
different than the scope of other types? Tag: Displaying version info onto a label Tag: 61889
free control alterative to treeview
does anybody of the existance of a free control that is a good
alternative to the treeview
i basically want some flexibility in the UI and ability to do
multiselect etc etc.
in delphi some guy had made a free virtual tree view that just rocked
and i'm looking to see if some people have stepped up to the mark in
C#
Karl Tag: Displaying version info onto a label Tag: 61888
image of button
I find that when a button is disabled, the image on the button will not
display and turn into a mess of grey color, is there anything we can do so
that the image can be visible or fade out or change to another image in
order to indicate that the button is disabled rather than turn into a mess
of grey.
Thz Tag: Displaying version info onto a label Tag: 61887
Main Form Unresponsive
I'm building a custom install program that allows the user
to select which assemblies get installed. In creating the
prototype I am encountering a situation where the main
form will not accept user input after the installation is
complete.
In my form, pressing the 'Install' button runs the
following method:
public override bool Install()
{
IDictionary savedState = new Hashtable();
System.Configuration.Install.AssemblyInstaller ai = new
System.Configuration.Install.AssemblyInstaller();
try
{
ai.Path = "testassembly.dll";
ai.UseNewContext = true;
ai.Install(savedState);
ai.Commit(savedState);
ai.Dispose();
return true;
}
catch (Exception e)
{
return false;
}
}
My trivial installer class is the only class in
the "testassembly.dll" named above:
[RunInstaller(true)]
public class Installer1 :
System.Configuration.Install.Installer
{
public Installer1()
{
}
public override void Install(IDictionary stateSaver)
{
base.Install (stateSaver);
MessageBox.Show("Installing", "TestAssembly");
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall (savedState);
MessageBox.Show("Installing", "TestAssembly");
}
}
After the install MessageBox is dismissed, the main form
gets updated (progress bar goes away and a 'Done' button
is made visible) correctly, but when I try to either click
the 'Done' button to exit the app, or close the form,
nothing happens.
If I remove the MessageBox from the installer class, then
everything works correctly and I can exit the app, so I
assume that there is some sort of forms or event loop
issue going on, but I have not been able to figure it out.
Anyone have any ideas?
Matt Tag: Displaying version info onto a label Tag: 61883
Main Form's Display chops Right Side & Bottom
Hello,
It seems that on a certain machine (i.e. Dell Dimension
4500S) when the main form is displayed (it initially
comes up maximized, and AutoScale is True per the
default - not that I truly grasp its significance) parts
of the right and bottom portions of the form are not
being displayed at all in the window. They seem to have
been truncated from the display.
I have a textbox that is located (and anchored) on the
far right-hand side of the form and when it comes up more
than half of the text is just chopped off (a good 2
logical inches or so). The bottom of the form has two
rows of icons (24x24) that don't show up at all (these
icons are also anchored to the bottom of the form).
You can't ever get the form to show any of the "lost"
area either (ie. by resizing, minimizing, maximizing,
etc.).
Has anyone seen this behavior at all or has any ideas as
to what is causing this behavior? Is there some known
issues with cetain computer's video drivers (this Dell
Dimensions uses an Intel video driver) and .NET. After
looking around on the net I haven't seen this addressed.
On this particular machine "normal" apps seem to work
fine and this is the first .NET form application it's
ever seen.
Thanks for any help/insight,
JB Tag: Displaying version info onto a label Tag: 61878
Maximum height of windows form
Hi,
I am trying to set the height of a form in the VS .net IDE, and somehow seem
unable to set the height beyond 780. I have set the autoscale and autoscroll
properties to true, and the Miniumn size and maximum size are set to 0,0
each. I was under the impression that with these settings I could make the
form as big as I wanted, and could get the scrollbars automatically when
needed. However this doesnt seem to be happening. The height gets reset to
780 if i type in anything bigger than that.
Am I missing something here ? Does anyone have an idea why I see such
behavior ?
Thanks in advance for any help,
Aniket Sule Tag: Displaying version info onto a label Tag: 61876
Is there any way to get an MDI child window to flash, like with FlashWindowEx()?
With FlashWindowEx(), I can make dialogs flash (like yahoo chat and stuff
like that). Is there any way to get an MDI child window to flash in the
same way? FlashWindowEx() doesn't work on child windows... Tag: Displaying version info onto a label Tag: 61873
Selecting Listview Item by Text
I have a listview with items Apple, Pear, Banana. How can I
programmatically select Pear if I don't know the index?
Thanks,
Todd Tag: Displaying version info onto a label Tag: 61868
OnPaint when using Offscreen bitmap
I am using an offscreen bitmap and I have scrolling.
For now I DrawImage the entire offscreen bitmap -- but that is slow.
Could anyone please tell me how to only DrawImage the portion I need so it
will go faster.
Thank you!
For now I do:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.TranslateTransform(
AutoScrollPosition.X, AutoScrollPosition.Y);
e.Graphics.DrawImage(offScreenBmp, 0, 0);
System.Drawing.Size s = new System.Drawing.Size();
s.Width = 0;
s.Height = 2100;
AutoScrollMinSize = s;
} Tag: Displaying version info onto a label Tag: 61861
Problems with MessageBox.Show
I'm experiencing a problem where I have a non-modal toolwindow that contains
a control derived from System.Windows.Forms.ComboBox displayed in an MDI
application. Whenever a .NET message box is displayed in the application the
derived combo boxes on the toolwindow appear to lose their base control,
i.e. base.WndProc(ref m) in the derived control's WndProc results in a
NullReferenceException. Admittedly this could be a problem with the derived
controls, however after looking at how System.Windows.Forms.MessageBox works
it seems like there are some "oddities". Also, if I call the Win32
MessageBox function directly via p/invoke, specifying the correct owner
window, then everything works fine.
Here is the section of System.Windows.Forms.MessageBox (ShowCore) that I've
been looking at:
if ((owner != null) && ((options & 2228224) != 0))
throw new ArgumentException(SR.GetString("CantShowMBServiceWithOwner"),
"style");
IntSecurity.SafeSubWindows.Demand();
num1 = (((buttons | icon) | defaultButton) | options);
ptr1 = IntPtr.Zero;
if ((options & 2228224) == 0)
{
if (owner == null)
ptr1 = UnsafeNativeMethods.GetActiveWindow();
else
ptr1 = owner.Handle;
}
Application.BeginModalMessageLoop();
result1 = MessageBox.Win32ToDialogResult(SafeNativeMethods.MessageBox(new
HandleRef(owner, ptr1), text, caption, num1));
Application.EndModalMessageLoop();
return result1;
The value of 2228224 corresponds to MessageBoxOptions.DefaultDesktopOnly |
MessageBoxOptions.ServiceNotification. The interesting thing here is that
the owner parameter is always ignored since owner must be null when options
contains the above flags. If owner is not null, the handle is never
retrieved because options cannot also contain the above flags and therefore
ptr1 remains as IntPtr.Zero. The other interesting thing is the
BeginModalMessageLoop/EndModalMessageLoop block. It appears as though this
disables all windows in the current thread, although I haven't looked at
this too deeply, and this further implies that the owner parameter plays no
part in establishing modality. Does anyone have any thoughts on this,
particularly with reference to the fact that the
BeginModalMessageLoop/EndModalMessageLoop block appears to be causing severe
problems for my non-modal windows? A single call to the Win32 MessageBox
function with a correctly specified owner window does not exhibit the same
problems.
TIA.
--
Kevin Westhead Tag: Displaying version info onto a label Tag: 61859
PropertyGrid customization
Hi,
I'm in the process of customizing the PropertyGrid for an
application. I've written several TypeConverters and a
few editors to display and process data within the grid.
What I haven't been able to do yet is have the editor
control receive the mouse input from another window.
For example, I have a CAD app and I want modify a line
entity. I select the entity and its properties are
displayed in the PropertyGrid. I select the beginning
coordinate field in the PropertyGridwant to modify the
coordinate of the beginning point by selecting the
location in the graphics window. Is this possible, or do
I just need to create my own custom version of the
PropertyGrid??
What I would ideally like to do is embed an existing
custom control inside the PropertyGrid.
TIA,
Peter Tag: Displaying version info onto a label Tag: 61851
Preventing "ding!" on Esc or Enter in a textbox
Anybody know how to prevent the ding sound from happening when the escape or
enter key is entered into a textbox? I need to catch the enter and escape
keys for processing.
I've the following event handler for on the Keydown event of the text box,
but I'm still getting the ding sound.
private void EditBoxKeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
if ( e.KeyCode == Keys.Enter )
{
/* do some processing */
e.Handled = true;
}
if ( e.KeyCode == Keys.Escape )
{
/* do some processing */
e.Handled = true;
}
} Tag: Displaying version info onto a label Tag: 61848
Form Start Position question
When I set the StartPosition on my main form to CenterScreen, the form never
starts at center screen, but offset toward the lower right corner. On my
modal login form, however, the property seems to work just fine.
Am I overlooking something??
Thanks! Tag: Displaying version info onto a label Tag: 61846
Form Scrolling
I have scrolling in my app.
When I click the arrows of the scroll bar or click inside the scroll bar the
app scrolls -- but when I drag the scroll box (that part in the middle) the
app does not scroll until after I release the mouse button. I'd like it to
scroll as I drag that scroll box. I figure I could just call this.refresh
but I do not see any events for the Form that fire while dragging that box?
Thank you. Tag: Displaying version info onto a label Tag: 61843
Call another form
Hi
I created two forms in the same proyect and I want to call
one form from another one but I couldn't find the Show
method. I'm working with C#.
In Visual Basic 6 you can tell the proyect which form use
first.
Regards Tag: Displaying version info onto a label Tag: 61838
Custom Authentication
I have a project where I have to build an internet cafe type program. I am
having a problem figuring out how to authenticate at user stations .
What I want to do is client machine to be locked and needs a temporary
password to get in. I am not sure how to lock the workstation. I am not just
looking for a solution, but suggestions. I have looked in google but I am
not sure what I am looking for. Any ideas?
John Tag: Displaying version info onto a label Tag: 61837
NumericUpDown Control bug
Hi,
I am using a control derived from NumericUpDown control
and when I click on the arrow and keep clicking on it for
long it crashes giving following error :
System.NullReferenceException: Object reference not set to
an instance of an object.
at System.Windows.Forms.UpDownButtons.TimerHandler
(Object source, EventArgs args)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)
Can anyone tell me how to fix this? I want to just handle
this exception so that it stops cpmplainng but don't know
what event to handle.
Thanks in advance for the help.
Gudia Tag: Displaying version info onto a label Tag: 61836
Custom painting in TextBox
Hello
I have a new class which inherits from TextBox and
implements a numeric textbox which have to allow the user
to input signed numbers. The control of key input is OK.
The problem is how to implement the display of the sign
character. I am planning to enabled this feature by
allowing the pressing of plus and minus keys (+ and -).
When the user hits the minus key, the negative sign
appears at the left side of the number; when he hits the
plus key, no sign is shown in the textbox.
This means that changing the left margin of the textbox is
not enough to make this feature work because the textbox's
default alignment is at the right side, and, in addition,
the textbox must allows the programmer to change the
text's alignment.
I do not want to include the negative sign character in
the text because of the lot of code I will have to write
in order to control user key hitting. I am thinking about
just painting the negative sign character at the left side
of the text, without including it in the text, by handling
some paint event.
Does somebody knows some guidelines on how can I do this?
Celio C Jr Tag: Displaying version info onto a label Tag: 61835
System.Windows.Forms.MdiClient+ControlCollection not serializable.
Scenario:
---------
I have an Explorer style application.
The app hosts other win forms by making them MDI children, removing border /
control box / minimize / maximize, and setting the form's Dock property to
Fill.
I have recently upgraded my application in the following way:
-------------------------------------------------------------
The MDI child forms are now contained within separate dynmically loaded
assemblies. My host application creates a new application domain to load the
assemblies into. A new instance of the child form is created within the
context of the new application domain, then my host application communicates
with that object via Remoting (cross AppDomains).
Problem:
---------
I can no longer set the MDI Child form's MdiParent property to my host app
because my host app's ControlCollection is not serializable, and I get a
SerializationException thrown.
I either need to:
- Find a way to set my remote MDI child's "MdiParent" property, or
- Use the Win32 Api to create the child form as an MDI Child without adding
it to my host application's MdiChildren collection. I don't really know how
to do this, and am not sure it is even possible when using WinForms.
Any suggestions?
Trevor Germain, CET, MCP
i-Gen Solutions, Inc. Tag: Displaying version info onto a label Tag: 61830
OLE in Windows Form
How can insert an OLE object in a Windows Form?
If visual basic 6.0 you could use the OLE Control to a complish the same
task Tag: Displaying version info onto a label Tag: 61824
Serialiazing a form
Hi,
i want to persist a few properties of a form ...how do i do it ? any
leads is greatly appriciated
regards,
... Tag: Displaying version info onto a label Tag: 61778
Changing TextBox left margin
Hello,
How can I change the TextBox's left margin so I can create
an inherited class from TextBox and paint something on its
left side?
Thank you.
Celio C Jr Tag: Displaying version info onto a label Tag: 61768
How can I capture rows changing in datagrid (winforms) when arrow up/down is pressed?
I update a form with labels and text boxes when the user clicks on the
rowheader of my winforms datagrid. I notice that the user can move to
a new row using the arrow up/down keys. I currently update the form
using the click event of the datagrid. How can I update the form when
the user moves to a new row using the arrow keys? In other words, I
need to capture the arrow keys when the datagrid is active or when a
new row is selected. BTW, I am using C#, however, if a VB.Net
developer has a solution, please reply. I can always convert the
code. Tag: Displaying version info onto a label Tag: 61758
SqlDataAdapter.RowUpdated Event
Hi,
Strangely enough, I cannot get the RowUpdated and RowUpdating events of a SqlDataAdapter to fire. I have done the standard subscribing to the event, and connecting the event handlers. But nothing happens.
Any help would be greatly appeciated.
Thanks,
Mark
Within a procedure:
daPersonPhone.RowUpdated +=new SqlRowUpdatedEventHandler(OnRowUpdated);
daPersonPhone.RowUpdating +=new SqlRowUpdatingEventHandler(OnRowUpdating);
The event handlers:
private void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e)
{
if (e.StatementType == StatementType.Insert)
{
if (e.RecordsAffected == 1)
{
int newOrderID = (int)e.Row["OrderID"];
DataRow newRow = dsOriginal.Tables["Phone"].Rows.Find(dummyPhoneID);
newRow["OrderID"] = newOrderID;
}
}
}
private void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
if (e.StatementType == StatementType.Insert)
dummyPhoneID = (int)e.Row["PhoneID", DataRowVersion.Current];
}
**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources... Tag: Displaying version info onto a label Tag: 61755
Web Services: How slow/fast they are
Subject: Windows distributed app
Data layer: SQL Server ( on separate machine )
Middle layer: WebServices on IIS ( on separate machine )
Questions:
1) How much Web Service are faster/slower compared to
other solutions for middle layer. Are there some (
benchmark or similar ) results which can at least
indicate me that figures.
2) How to configure Web Server ( machine resoureces and
Set up ) to get fastes possible Web Server - Web Services
response. The case could be system with up to 200 WinForm
Clients.
Thank you in advance
Gisa Tag: Displaying version info onto a label Tag: 61754
IDisposable, using(), RAII and structs [Discussion]
Last night I had several thought about RAII and want to discuss a bit.
Why doesn't CSharp support destructors in structs? Wouldn't that make RAII
possible like in C++? When the struct goes out of scope, the dtor could be
immediately be called (no GC needed).
For that, you don't have to declare the whole File class as a struct (which
would be not good for performance when File has a lot of data-members).
Instead creating a thin wrapper would be a good solution:
public struct MyFile
{
File f;
public MyFile(string p) { f=new File(p); }
~MyFile() { f.Close(); }
}
That would do it.
I have a second though which got through my mind. What about introducing an
interface which is recognized by the compiler and forces usage of the
using() statement.
public interface IDisposableForce : IDisposable{}
A second possibility could be declaring an attribute which marks
IDisposable-implementing-classes wheather using() should be mandatory or at
least suggested.
enum WarnLevel {NoWarn,WarnLvl1,WarnLvl2,WarnLvl3,WarnLvl4,GenerateError};
class UsingAttribute{UsingAttribute(WarnLevel w){}}
[Using(WarnLvl3)] // that means if warnlevel 3 or higher is set a warning
is issued when this class is used without using()-statement
public class MyFile : File
{
public class MyFile(string p) :base(p){}
}
What do you think?
--
cody
[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk Tag: Displaying version info onto a label Tag: 61739
Selecting Text
I have a basic app that draws some text: Graphics.DrawString(...).
I want to be able to mouse select that text and copy to clipboard. Does
anyone know of any sample info on doing that.
Thank you. Tag: Displaying version info onto a label Tag: 61733
Full dataset into an empty SQL table
Hi,
I managed to create a SQL server database and a table in it. The table is
empty and that brings me to my next chalenge:
How can I get the info in the table in the dataset to go in an empty SQL
table?
Is there a short way like the FILL method to get data into the dataset or do
I have to read each datarow in the table and write it one at the time to the
database?
rg,
Eric Tag: Displaying version info onto a label Tag: 61724
[urgent] Message Box is non-modal in VB!
Hi,
In some situation, the message box can not be shown in modal mode.
Please drop a DateTimePicker control on a Form (VB project), show a
message box in the ValueChanged event, as below snippet. Now run the form
and drop down the calendar, select a date to let the event fire, after the
message box shown, we can still activate the form background. This happens
whatever MsgBoxStyle is specified even as MsgBoxStyle.SystemModal.
Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles DateTimePicker1.ValueChanged
MsgBox("DateTimePicker1_ValueChanged", MsgBoxStyle.ApplicationModal)
End Sub
The same scenario could be reproduced in a C# project, but I could pass it
if by specifying the Form as the owner of the message box, as below code.
private void dateTimePicker1_ValueChanged(object sender, System.EventArgs
e)
{
MessageBox.Show(this, "dateTimePicker1_ValueChanged");
}
Is something wrong in the message box method in VB?
-jason Tag: Displaying version info onto a label Tag: 61721
Button.TextAlign bug?
Hi,
I'm using C# and VS.net 2003. When adding a button to a
form using the designer, the default TextAlign value is
always set to MiddleCenter (which is fine). However, if I
change the font to be bold, the text is no longer center-
aligned, it is always a bit off to the right, more or
less depending on the string value. The TextAlign
property is still MiddleCenter though. Is this a known
bug?
Thanks,
Henrik Tag: Displaying version info onto a label Tag: 61711
A From won't close (c#)
Hello everyone,
I have main application form (child of System.Windows.Forms.Form) that
hosts quite a number of different visual components. Some time after
working with those components, the form refuses to be closed - I click
menu item that invokes Form.Close() method, I click 'close' icon on
the caption of the window (form) - nothing happens. No event comes to
Form_Closing(Object, CancelEventArgs) method either.
I'm at a loss how to even start debugging this situation and I would
appreciate any suggestions.
Thank you for your time,
Yuriy ZUbarev Tag: Displaying version info onto a label Tag: 61707
DataReader and ListBox
oh come on. I have to be missing something.
There HAS to be a better way of binding data to a winform listbox that
reading through all the records and adding each item to the items
collection.
Its .NET for crying out loud. Tag: Displaying version info onto a label Tag: 61706
How to force window to Maximize
Hi,
I would like to force my application to maximize when it is launched. I
have tried this by setting the WindowState in the designer at runtime, and
have also tried executing
WindowState = FormWindowState.Normal
The form does open maximized but it does not correctly maximize to the
Windows taskbar...the bottom of the form is lost under the taskbar. If I
use the form control menu to set the form to normal and then back to
maximized, it correctly fits into the available desktop area, only going up
to the top of the taskbar. Any ideas why???
Also I want to stop the user setting the window state to normal - I either
want it maximized or minimized, but never normal. If the user
double-clicks the Window title it does set the window state to normal. Is
there an easy way to prevent this from happening???
Many thanks. Tag: Displaying version info onto a label Tag: 61704
Check for illegal char in DataGridTextBoxColumn
Hi all, need some help in taking the right approach to
solve this problem.
I have a DataGrid bound to a DataTable. I need the user to
enter only numerical values and decimal. I did override
the ProcessCmdKey of DataGrid. I'm capturing Enter, Tab,
directinal and other keys. If the user enters an invalid
key, I need to prompt him. But, for this I'll need to map
all the other keys to be invalid in my code. Is there any
other slick way of doing this.
Code attached.
protected override bool ProcessCmdKey(ref Message msg,
Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
int rowNum = dGInput.CurrentCell.RowNumber;
int colNum = dGInput.CurrentCell.ColumnNumber;
if ((colNum == 2) || (colNum == 5))
{
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch(keyData)
{
case Keys.D0:
case Keys.D1:
case Keys.D2:
case Keys.D3:
case Keys.D4:
case Keys.D5:
case Keys.D6:
case Keys.D7:
case Keys.D8:
case Keys.D9:
case Keys.NumPad0:
case Keys.NumPad1:
case Keys.NumPad2:
case Keys.NumPad3:
case Keys.NumPad4:
case Keys.NumPad5:
case Keys.NumPad6:
case Keys.NumPad7:
case Keys.NumPad8:
case Keys.NumPad9:
case Keys.Decimal:
case Keys.OemPeriod:
break;
case Keys.Back:
break;
case Keys.Down:
case Keys.Up:
case Keys.Left:
case Keys.Right:
case Keys.Enter:
case Keys.Tab:
UpdateDataGridCell(rowNum,colNum);
break;
default:
MessageBox.Show("Invalid character","Error");
break;
}
}
} Tag: Displaying version info onto a label Tag: 61703
Application Addins
I am interested in some resources to help in whether or not Addins to a
Windows Forms application is a good (solid) design to add functionality to
the application and also understanding the if anyone has had good and or bad
experiences.
Thanks in advance for all that participate.
Wade Tag: Displaying version info onto a label Tag: 61700
MSDN Sample - The ListManager's position must be equal to rowNum
Hi All,
I used DataGridComboBoxColumn from MSDN magazine (
http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx).
Normally things work fine.
but in the following cases I get an error 'The ListManager's
position must be equal to rowNum'.
================================
1) when I click on a comboboxcolumn cell
2) and scroll the datagrid
3) and click on another comboboxcolumn cell
OR
1) navigate to a tabpage other than the one datagrid is on
2) and navigate back to datagrid tabpage
3) and click on a comboboxcolumn cell
================================
Good news is I made a change to the code and the problem went away.
The bad news is I can't understand why!
Just wonder if the experts here might be able to help?
The change that I made to DataGridComboBoxColumn are
1) remove combobox.hide from datagrid_scroll event
2)add code in edit method to hide the combo when current cell is not
visible
(I'll attach both codes)
I have trace output for the following sequence of action
1) click on datagridcombobox column cell at row 3 (index 2)
2) then click on datagridcombobox column cell at row 5 (index 4)
3)scroll one cell
4)then click on datagridcombobox column cell at row 6 (index 5)
==============TRACE OUTPUT ORIGINAL CODE====================raises
the error
Edit 2
Leave: column1 column1
SetColumnValueAtRow 2 column1
Edit 4
-------------I scroll now
Edit 4
Leave: column1 column1
SetColumnValueAtRow 4 column1
Scroll
-------------combo hidden is hidden now
Leave: column1 column1
SetColumnValueAtRow 4 column1
Edit 4 <------things start to go wrong here? why is it entering edit
4...when it should be going to edit 5
Edit 5
Leave: column1 column1
SetColumnValueAtRow 4 column1
===============TRACE OUTPUT MODIFIED CODE====================no
errors raised here
Edit 2
Leave: column1 column1
SetColumnValueAtRow 2 column1
Edit 4
-------------scroll
Edit 4
Leave: column1 column1
SetColumnValueAtRow 4 column1
Scroll
-------------combo stays
Leave: column1 column1
SetColumnValueAtRow 4 column1
Edit 5
==================================
notice that things start to go a bit crazy in last 3-4 lines. The thing that
seems to cause the error is Edit method being called in the first case for
rowindex 4 and then rowindex5 immediately....unlike the second case....
It may not make much sense w/o the code so I attach both cases with the
mail.
====================ORIGINAL CODE===================
// Derive class from DataGridTextBoxColumn
public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
// Hosted ComboBox control
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;
// Constructor - create combobox, register selection change event handler,
// register lose focus event handler
public DataGridComboBoxColumn()
{
this.cm = null;
// Create ComboBox and force DropDownList style
this.comboBox = new ComboBox();
this.comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
// Add event handler for notification of when ComboBox loses focus
this.comboBox.Leave += new EventHandler(comboBox_Leave);
}
// Property to provide access to ComboBox
public ComboBox ComboBox
{
get { return comboBox; }
}
// On edit, add scroll event handler, and display combo box
protected override void Edit(System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string
instantText, bool cellIsVisible)
{
Debug.WriteLine(String.Format("Edit {0}", rowNum));
base.Edit(source, rowNum, bounds, readOnly, instantText, cellIsVisible);
if (!readOnly && cellIsVisible)
{
// Save current row in the datagrid and currency manager associated with
// the data source for the datagrid
this.iCurrentRow = rowNum;
this.cm = source;
// Add event handler for datagrid scroll notification
this.DataGridTableStyle.DataGrid.Scroll += new
EventHandler(DataGrid_Scroll);
// Site the combo box control within the bounds of the current cell
this.comboBox.Parent = this.TextBox.Parent;
Rectangle rect = this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
this.comboBox.Location = rect.Location;
this.comboBox.Size = new Size(this.TextBox.Size.Width,
this.comboBox.Size.Height);
// Set combo box selection to given text
this.comboBox.SelectedIndex =
this.comboBox.FindStringExact(this.TextBox.Text);
// Make the ComboBox visible and place on top text box control
this.comboBox.Show();
this.comboBox.BringToFront();
this.comboBox.Focus();
}
// else
// {
// this.comboBox.Hide();
// }
}
// Given a row, get the value member associated with a row. Use the value
// member to find the associated display member by iterating over bound
datasource
protected override object
GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{
//Debug.WriteLine(String.Format("GetColumnValueAtRow {0}", rowNum));
// Given a row number in the datagrid, get the display member
object obj = base.GetColumnValueAtRow(source, rowNum);
// Iterate through the datasource bound to the ColumnComboBox
// Don't confuse this datasource with the datasource of the associated
datagrid
CurrencyManager cm = (CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);
// Assumes the associated DataGrid is bound to a DataView, or DataTable that
// implements a default DataView
DataView dataview = ((DataView)cm.List);
int i;
for (i = 0; i < dataview.Count; i++)
{
if (obj.Equals(dataview[i][this.comboBox.ValueMember]))
break;
}
if (i < dataview.Count)
return dataview[i][this.comboBox.DisplayMember];
return DBNull.Value;
}
// Given a row and a display member, iterating over bound datasource to find
// the associated value member. Set this value member.
protected override void
SetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum,
object value)
{
Debug.WriteLine(String.Format("SetColumnValueAtRow {0} {1}", rowNum,
value));
object s = value;
// Iterate through the datasource bound to the ColumnComboBox
// Don't confuse this datasource with the datasource of the associated
datagrid
CurrencyManager cm = (CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);
// Assumes the associated DataGrid is bound to a DataView, or DataTable that
// implements a default DataView
DataView dataview = ((DataView)cm.List);
int i;
for (i = 0; i < dataview.Count; i++)
{
if (s.Equals(dataview[i][this.comboBox.DisplayMember]))
break;
}
// If set item was found return corresponding value, otherwise return
DbNull.Value
if(i < dataview.Count)
s = dataview[i][this.comboBox.ValueMember];
else
s = DBNull.Value;
base.SetColumnValueAtRow(source, rowNum, s);
}
// On datagrid scroll, hide the combobox
private void DataGrid_Scroll(object sender, EventArgs e)
{
Debug.WriteLine("Scroll");
this.comboBox.Hide();
}
// On combo box losing focus, set the column value, hide the combo box,
// and unregister scroll event handler
private void comboBox_Leave(object sender, EventArgs e)
{
DataRowView rowView = (DataRowView) this.comboBox.SelectedItem;
string s = (string) rowView.Row[this.comboBox.DisplayMember];
Debug.WriteLine(String.Format("Leave: {0} {1}", this.comboBox.Text, s));
SetColumnValueAtRow(this.cm, this.iCurrentRow, s);
Invalidate();
this.comboBox.Hide();
this.DataGridTableStyle.DataGrid.Scroll -= new
EventHandler(DataGrid_Scroll);
}
}
===================================MODIFIED
CODE=========================================
// Derive class from DataGridTextBoxColumn
public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
// Hosted ComboBox control
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;
// Constructor - create combobox, register selection change event handler,
// register lose focus event handler
public DataGridComboBoxColumn()
{
this.cm = null;
// Create ComboBox and force DropDownList style
this.comboBox = new ComboBox();
this.comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
// Add event handler for notification of when ComboBox loses focus
this.comboBox.Leave += new EventHandler(comboBox_Leave);
}
// Property to provide access to ComboBox
public ComboBox ComboBox
{
get { return comboBox; }
}
// On edit, add scroll event handler, and display combo box
protected override void Edit(System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string
instantText, bool cellIsVisible)
{
Debug.WriteLine(String.Format("Edit {0}", rowNum));
base.Edit(source, rowNum, bounds, readOnly, instantText, cellIsVisible);
if (!readOnly && cellIsVisible)
{
// Save current row in the datagrid and currency manager associated with
// the data source for the datagrid
this.iCurrentRow = rowNum;
this.cm = source;
// Add event handler for datagrid scroll notification
this.DataGridTableStyle.DataGrid.Scroll += new
EventHandler(DataGrid_Scroll);
// Site the combo box control within the bounds of the current cell
this.comboBox.Parent = this.TextBox.Parent;
Rectangle rect = this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
this.comboBox.Location = rect.Location;
this.comboBox.Size = new Size(this.TextBox.Size.Width,
this.comboBox.Size.Height);
// Set combo box selection to given text
this.comboBox.SelectedIndex =
this.comboBox.FindStringExact(this.TextBox.Text);
// Make the ComboBox visible and place on top text box control
this.comboBox.Show();
this.comboBox.BringToFront();
this.comboBox.Focus();
}
else
{
this.comboBox.Hide();
}
}
// Given a row, get the value member associated with a row. Use the value
// member to find the associated display member by iterating over bound
datasource
protected override object
GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{
//Debug.WriteLine(String.Format("GetColumnValueAtRow {0}", rowNum));
// Given a row number in the datagrid, get the display member
object obj = base.GetColumnValueAtRow(source, rowNum);
// Iterate through the datasource bound to the ColumnComboBox
// Don't confuse this datasource with the datasource of the associated
datagrid
CurrencyManager cm = (CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);
// Assumes the associated DataGrid is bound to a DataView, or DataTable that
// implements a default DataView
DataView dataview = ((DataView)cm.List);
int i;
for (i = 0; i < dataview.Count; i++)
{
if (obj.Equals(dataview[i][this.comboBox.ValueMember]))
break;
}
if (i < dataview.Count)
return dataview[i][this.comboBox.DisplayMember];
return DBNull.Value;
}
// Given a row and a display member, iterating over bound datasource to find
// the associated value member. Set this value member.
protected override void
SetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum,
object value)
{
Debug.WriteLine(String.Format("SetColumnValueAtRow {0} {1}", rowNum,
value));
object s = value;
// Iterate through the datasource bound to the ColumnComboBox
// Don't confuse this datasource with the datasource of the associated
datagrid
CurrencyManager cm = (CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);
// Assumes the associated DataGrid is bound to a DataView, or DataTable that
// implements a default DataView
DataView dataview = ((DataView)cm.List);
int i;
for (i = 0; i < dataview.Count; i++)
{
if (s.Equals(dataview[i][this.comboBox.DisplayMember]))
break;
}
// If set item was found return corresponding value, otherwise return
DbNull.Value
if(i < dataview.Count)
s = dataview[i][this.comboBox.ValueMember];
else
s = DBNull.Value;
base.SetColumnValueAtRow(source, rowNum, s);
}
// On datagrid scroll, hide the combobox
private void DataGrid_Scroll(object sender, EventArgs e)
{
Debug.WriteLine("Scroll");
// this.comboBox.Hide();
}
// On combo box losing focus, set the column value, hide the combo box,
// and unregister scroll event handler
private void comboBox_Leave(object sender, EventArgs e)
{
DataRowView rowView = (DataRowView) this.comboBox.SelectedItem;
string s = (string) rowView.Row[this.comboBox.DisplayMember];
Debug.WriteLine(String.Format("Leave: {0} {1}", this.comboBox.Text, s));
SetColumnValueAtRow(this.cm, this.iCurrentRow, s);
Invalidate();
this.comboBox.Hide();
this.DataGridTableStyle.DataGrid.Scroll -= new
EventHandler(DataGrid_Scroll);
}
}
Thanks if you've got here... :-)
GK Tag: Displaying version info onto a label Tag: 61697
typed dataset on inherited form
There is obviously a bug in VS.NET 2003:
Steps to reproduce:
1.) Create typed DataSet with one unique key.
2.) Make WinForm and place a (visual) instance of the
typed DataSet on it.
3.) Create an inherited form (base on the first form).
4.) Place any control (button,...) on the second form.
When running the test-app, an exception is thrown.
(System.ArgumentException: Cannot add primary key
constraint since primary key is already set for the
table.)
Reason: VS generates code in the inherited form for the
dataset, which will add the same constraint again to the
dataset.
I found a thread, reporting this topic:
http://groups.google.at/groups?threadm=009801c31794%
24f74a5bb0%242f01280a%40phx.gbl
This thread is from May 03 and it says, that this is a
known bug and a KB-article regarding this issue is going
to be published. But I could not find anything! :(
Are there any solutions to this problem yet???
Thanks for any answer!!
Thomas Tag: Displaying version info onto a label Tag: 61696
window form style question
I am using VS.net 2003 to develop a simple window form by
using C#. I have added a menu in that simple window, as
follow:
http://destiny.xfiles.to/ubbthreads/files/383648-2.jpg
The style is the standard one, but i would like to change
to VS.net style, just like the following:
http://destiny.xfiles.to/ubbthreads/files/383646-1.jpg
how can i change the standard style to VS.net style?
thank you. Tag: Displaying version info onto a label Tag: 61689
> Hello,
>
> I am trying to figure out how to display the applications version
> information onto a label. How would I do this?
>
> -T
Look into System.Reflection.Assembly class.
Assembly.GetStartingAssembly().GetName() returns(among other info) what you
need.
--
Roy Osherove
weblog: http://www.iserializable.com
Re: Displaying version info onto a label by hirf-spam-me-here
hirf-spam-me-here
Tue Nov 25 10:54:58 CST 2003
* "TGF" <tfitz@engr.uconn.edu[remove brackets]> scripsit:
> I am trying to figure out how to display the applications version
> information onto a label. How would I do this?
'System.Reflection.Assembly.GetExecutingAssembly().GetName().Version' or
'Application.ProductVersion'.