|
Hi,
We have a Windows Forms project with quite a few flatstyle buttons.
When we disable the buttons, the colors of the buttons are changed automatically
Is it possible to override this somehow, so we can control the colors ourselves?
Thanks,
Karl
|
|
|
|
|
You could create your own buttons, the simplest way is to inherit from Button and override some functions:
public class BernieButton : Button
{
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
....
}
}
|
|
|
|
|
Yeah, that's the expected behavior. It's the standard notification to the user that the button will no longer work in the current situation.
Why would you want to change this?? If you don't change the color, the user will wonder what's wrong with your app because they think they're clicking on an active button and nothing is happening!
|
|
|
|
|
In fact the BackColor of control doesn't change and only ForeColor and BorderColor change.
Set FlatStyle to Flat, Set a non system BorderColor in FlatAppearance, Set a non system BackColor and you will see background and border will not change.
Only ForeColor changes to show difference of enabled and disabled button.
|
|
|
|
|
i create control and this control derived from gridview control.then i add 2 column in constructor like this :
InitializeComponent();
this.AutoGenerateColumns = false;
DataGridViewCheckBoxColumn cb = new DataGridViewCheckBoxColumn();
cb.HeaderText = "";
cb.Name = "dgvcSelect";
this.Columns.Add(cb);
DataGridViewTextBoxColumn tb = new DataGridViewTextBoxColumn();
tb.Name = "dgvcRowNumber";
tb.HeaderText = "ردیف";
but when i run my program 4 column generate for me.where is the problem?
please help me
|
|
|
|
|
Don't cross post in multiple forums.
Pick one forum best suited to your question and post your question once!
|
|
|
|
|
Need a bit more of the code the way this code looks is that you have created two columns but can't see enough to know what is happening.
Please post the entire scope of the problem so we can help.
Thanks
JD
http://www.seitmc.com/seitmcWP
|
|
|
|
|
You realize that this post is over 6 months old, right? Chances are good we'll never hear from his again.
|
|
|
|
|
HA! Well no I didn't look at the date. Doh! Just looking to do some give back.
Thanks
JD
http://www.seitmc.com/seitmcWP
|
|
|
|
|
Hi everybody,
I'm trying to bind a class variable to a textbox.
the data class looks like:
<pre lang="c#">
public class route
{
public string name { get; set; }
public int adress { get; set; }
public route()
{
name = "";
adress = 0;
}
}
public class adr
{
public int index { get; set; }
public route r1 { get; set; }
public route r2 { get; set; }
public adr()
{
index = 0;
r1 = new route();
r2 = new route();
}
}
public class para
{
public int i1 { get; set; }
public int i2 { get; set; }
}
public class adrData
{
public string label { get; set; }
public adr ad { get; set; }
public para pa { get; set; }
}
When I try to bind f.e. ad.r1.name to a textbox text via designer, it offers only label, ad and pa for binding.
What am I missing here?
Thnx adv for your answers.
modified 21-Jul-13 10:42am.
|
|
|
|
|
What type is "ad.r1.name"? As far as I can see from your code, there's only one "name" property, and that's a string, whereas the bindin-options imply that "name" contains an adrData ?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
its a tree structure:
the string name is an element of class route,
route r1 is an element of class adr,
adr ad is an element of class adrData.
|
|
|
|
|
First, I think you need to add a constructor to 'adrData:
public class adrData
{
public string label { get; set; }
public adr ad { get; set; }
public para pa { get; set; }
// ctor
public adrData()
{
label = "";
ad = new adr();
pa = new para();
}
} Then, in code, you can do something like this:
adrData newAdrData = new adrData();
newAdrData.ad.r1.name = "Route Name #1";
textBox1.DataBindings.Add("Text", newAdrData, "ad.r1.name"); To bind to a specific instance of 'adrData. Unless you create a new instance of 'ad, within 'adrData, then you never initialize the 'routes: because only creating a new instance of 'adr will initialize the 'routes.
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
|
|
|
|
|
Hi ,
At the moment I'm developing an Windows Form application and looking for a logger. I have seen log4c++ and boost.log, but both loggers won't work because some code isn't compatible with /clr code. Does somebody has a logger which is compatible with Windows forms?
|
|
|
|
|
|
Hello All,
I haven't coded a lot in Winforms C#. In any case I need to fetch a temporary stored image image from the local disk and process in a vendors API. Their method requires Bitmap bitmap for the parameters as indicated here(//vendor.Reader.AnalyzeField(Bitmap bitmap)).
// Example 1 - This works when I use hard coded texted.
// Example 2 fails attempting to use with the variable. The error is "Parameter is not valid".
1 - Bitmap btm = new Bitmap "C:\\Images\\2.tif");
// The variable fails here.
2 - Bitmap btm = new Bitmap(_transferFile);
//Perform recognition
result = vendor.Reader.AnalyzeField(btm);
Thanks in advance
modified 11-Jul-13 14:03pm.
|
|
|
|
|
fincity wrote: The error is "Parameter is not valid". Then you need to use a parameter that is valid, i.e. a Bitmap as specified in the method definition. You have not specified what type _transferFile is, but I assume it is not a Bitmap .
Use the best guess
|
|
|
|
|
You mean something similar to below code?
string fileName = "C:\\Images\\2.tif";
Bitmap btm = new Bitmap(fileName);
result = vendor.Reader.AnalyzeField(btm); Where is the initialization-code of your _transferFile member?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In Windows form , I'm displaying a Project_Table using tableAdapterManager.
I followed as per http://www.youtube.com/watch?v=3w2JkLcp-UA[^]
Project_Id int Primary Key with Identity specification as identity
Project_Name nvarchar(50)
Project_Type nvarchar(50)
Platform_Type nvarchar(50)
Start_Date date
Customer nvarchar(50)
In the code
private void project_TableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.project_TableBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.pLMDataSet);
}
I'm getting error Cannot insert explicit value for identity column in table 'Project_Table' when IDENTITY_INSERT is set to OFF
Even after executing following script I'm getting same error.
USE [PLM]
GO
SET IDENTITY_INSERT [dbo].[Project_Table] ON
go
Another table Phases_table has dependency on Project_Table through FK constraint. Is the error because of this constraint?
Are there any sample examples on C# with MSSQL database which use multiple windows forms with multiples table linked in an hierarchy?
|
|
|
|
|
Member 8387808 wrote: I'm getting error Cannot insert explicit value for identity column in table 'Project_Table' when IDENTITY_INSERT is set to OFF Means you're passing in a value for the primary key - but that column is readonly, as the database will generate a value for you.
Member 8387808 wrote: Another table Phases_table has dependency on Project_Table through FK constraint. Is the error because of this constraint? Can you explain me the difference between a PK and a FK? If not, no problem - we'll start there.
Member 8387808 wrote: Are there any sample examples on C# with MSSQL database which use multiple windows forms with multiples table linked in an hierarchy? Yes. Now a bit more specific, or I'll have to point to a random db-application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well, I'm plum out of ideas. I've got a listbox with a List<> for its DataSource. When I init it - before the form is displayed, it works. But not after that. I am modifying the List<> contents and then I run:
public void RefreshLbx()
{
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
}
where _quotes is the List<>
Now here is where it gets weird. I put a button on the form - here's its handler:
private void btnRefresh_Click(object sender, EventArgs e)
{
RefreshLbx();
}
So that when I click on the button then the lbxQuotes listbox is properly updated. But in the modification code - where I call RefreshLbx() directly, nothing happens.
I even tried invoking btnRefresh_Click() in the code, but alas could not find the magic.
Oh one other thought - the modification code is in a timer event handler - could this be a problem of trying to modify a control from a different thread? All I am doing is changing the List<> contents and then reseting the DataSource.
I must be missing something to kick the listbox to redisplay, or something... HELP!
|
|
|
|
|
Wow but this is weird. Okay, I found the solution because I tried the recommendation given below:
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
lbxQuotes.SelectionMode = SelectionMode.None;
lbxQuotes.SelectionMode = SelectionMode.One;
That is, I added the SelectionMode two lines... and this caused (only once) a "from different thread" exception. Weird, I'm NOT running a method - I'm changing data... hmmm... I wonder if the DataSource is instead a Property (which secretly runs a method). D'oh!
Okay, so the solution was to create a delegate in the main form, for the RefreshLbx method, and have the RefreshLbx method recursively call this, as below:
public void RefreshLbx()
{
if (lbxQuotes.InvokeRequired)
{
lbxQuotes.Invoke(_refreshLbx);
}
else
{
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
}
}
with the _refreshLbx delegate defined in the form's class as:
private delegate void RefreshLbxDg8();
private RefreshLbxDg8 _refreshLbx;
Then just init the delegate in the form constructor (after the InitializeComponent() call):
_refreshLbx = RefreshLbx;
Now I am able to update the listbox contents from a timer handler.
|
|
|
|
|
"System.Threading.Timer" is not threadsafe. You didn't use the Timer from the Toolbox, did you?
rbsbscrp wrote: Weird, I'm NOT running a method - I'm changing data... hmmm... You're changing a property from a different thread than where the control was created.
rbsbscrp wrote: if the DataSource is instead a Property (which secretly runs a method). Yup, it's a property; meaning it's built from two methods (not threads!)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You can NOT so much as touch ANY part of a control from a thread other than the one that created it, the UI (or startup) thread. This is where your entire problem comes from.
You have to Invoke methods on the UI thread that manipulates the control for your calling code.
|
|
|
|
|
My thanks to all who responded.
>>
You can NOT so much as touch ANY part of a control from a thread other than the one that created it, the UI (or startup) thread. This is where your entire problem comes from.
My confusion was mostly that I was not trying to run a Method at all - I was just changing a Property (or what I thought was DATA). Upon more consideration, I realized that a Property is just syntactic sugar over a procedure call, anyway, so the "you can't run code from a different thread" rule applied even changing a Property.
However, I am mystified as to WHY this rule "no touchie from different thread" even exists. Sure, if I'm trying to update a TextBox from other threads then there *could* be confusion and a random mix of characters added from the various threads due to the asynchronous timing of the code in the different threads. Yes, there *could* be... it is *possible* - just like I could really mess up a data structure if I update it from many threads without synchronization.
But that is exactly what multithreaded coding is all about - synchronizing the use of common data structures (at least it is a major issue, if not the biggest issue).
But why would the compiler assume that I am needing multithreading synchronization when updating a Textbox? The truth is, I am doing something at timed intervals - I am using a timer. It just so *happens* that C# chooses internally to implement a timer via a separate new thread. That is not *my* problem. I'm not trying to append text to the textbox from 17 different timers or asynchronous threads. I'm simply trying to update a textbox at constant intervals - in this case the system chooses to do this via ONE (other) thread.
Suddenly now I have to become fully knowledgeable about multithreading and delegates and "invoking", etc. BAH! Unnecessary, unneeded, unwanted complexification.
Aside from all that, I especially did not appreciate that the code simply failed to do anything - I got no compiler warning/error nor any runtime problem. My dialogbox simply didn't update. Then I had the fire up The Google and go searching for why it didn't work. My first real clue was that if I caused the update to happen from the very same function, via a click of a button on the UI, then it worked. Whaaa? My code definitely worked, but only if executed via a pushbutton.
I've coded for years, and I'm teaching myself C# now, and "yeah" this is a noobie kinda problem, but geeeez what an unnecessary timewaster.
Okay, 'nuff whining. Thx to all who replied. I found some code example for doing a "invoke" via a deleagate, etc., etc., and got it working.
|
|
|
|