|
Hi,
There is a Label control and I want to change its FontStyle (Bold, Italic, ...) at Runtime. But Font.Bold and Font.Italic are read-only properties.
How can I do it?
regards,
Mehdi.
|
|
|
|
|
label1.Font = new Font(label1.Font, FontStyle.Bold);
or
label1.Font = new Font(label1.Font, FontStyle.Italic);
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
I have class with certain properties, properties has certain attributes like DefaultValueAttribute ...now i have applied this attribute to one property...at runtime I want to change thie attribute meaning I want to change DefaultValueAttribute to some diff. value. How can I do it..?
- Atul Khalate
|
|
|
|
|
Sadly attributes can only be set at compile time
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
The attribute he's asking about in particular is only meaningful at design-time anyway, so it's unclear what he really wants.
-Blake
|
|
|
|
|
I'll ttry to clear my question here ...
I have defined one attribute,'GCDefaultValueAttribute',...which has one get/set property ,'Value',of type object.I have applied this attribute to property of class, 'Class1'.While applying attribute to this property I had passed some value (21)to the contructor of this attribute which will set the 'Value' property of GCDefaultValueAttribute. Now while loading an assembly in which this class is used,I want to change this default value from 21 to 26 for a class so that whenever new object created from this class it's property should have default value as 26 not 21 which was given at compile time.
Q1.Can I do it?
Q2.If "Yes" then How..?
Regards,
- Atul Khalate
|
|
|
|
|
I am leaving my current contract this week and I have documented my c# code to its eye teeth . But now they want a printed set of documentation so I have to print out the code comment report. Anyone know a good way of doing it ?
|
|
|
|
|
If you used the proper C# documentation syntax, you can use a popular project that I'm proud to be a part of called NDoc at http://ndoc.sourceforge.net[^]. This is widely used for C# projects by both major corporations and small projects alike. This can generate a CHM (for which the HTML Help view can print linear files) or other formats. A linear format is currently in beta stages but seems to work okay (just that the file is huge!). This won't use any internal comments, though, but I'm not sure if that's what you need.
Note: VS.NET has something similar but - as most people will agree - it's pretty basic and - to some extent - sucks.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi All!!
Well! I am developing a report designer like in Access but facing two problems.
1- I want to make my ToolBar Floating. So that my tools float over my designed area rather than making it fix on form.
2- on same designer I have to draw lines. when panel is repainted then all the lines disappear. SO i added them in an arraylist and repainted them all. But now whenever mouse is hovered over the panel all the lines start flickering.
Thanx in advance
sorry for my bad English.
|
|
|
|
|
Hi,
First of all, I'm new on CodeProject, so quick introducing: my names is Matthieu, I'm 26yo and live in France.
I start learning C# and I get stuck at the (easy?) following:
I have 2 string arrays, and I want to copy the first at the end of the second. I used Array.CopyTo method but it fails because the destination array is not large enough.
How can I increase the size of the dest string array ?
Thanks a lot for help,
Matthieu
|
|
|
|
|
Use Concat method of string.
s1= "Hello ";
s2 = "World"
s1 = s1.Concat(string2)
//s1 = Hello World
sorry for my bad English.
|
|
|
|
|
Thanks Itanium, but that's not what I want to do.
s1[0]="hello"
s1[1]="world"
s2[0]="good"
s2[1]="luck"
and I want to create a new string array like this:
s1[0]="hello"
s1[1]="world"
s1[2]="good"
s1[3]="luck"
Thanks a lot for help
Matthieu
|
|
|
|
|
you cannot re-dimension an array in C# like you could in VB with redim. You'll need to do something like:
string[] arrayOne = new string[]{"Hello", "World"};
string[] arrayTwo = new string[]{"Have", "a", "nice", "day"};
int newArrayLength = arrayOne.Length + arrayTwo.Length;
string[] arrayThree = arrayOne;
arrayOne = new String[newArrayLength];
int iterator = 0;
foreach(string s in arrayThree)
{
arrayOne[iterator] = s;
iterator++;
}
foreach(string s in arrayTwo)
{
arrayOne[iterator] = s;
iterator++;
}
I'm sure theres a more diginfied way, but it does work!!!
|
|
|
|
|
You've got two options here:
1. Create a new array of length= array1.length + array2.length, then use two consecutive Array.CopyTo() calls, one using zero as the index to start at, one using array1.length.
2. If you don't mind the minor performance hit from using a ICollection based object, take a look at System.Collections.ArrayList:
using System.Collections;
ArrayList array1 = new ArrayList();
array1.Add("hello");
array1.Add("world");
ArrayList array2 = new ArrayList();
array2.Add("Bonjour");
array2.Add("le monde");
array1.AddRange( array2 );
now array1 should contain (boxed as objects):
"hello",
"world",
"Bonjour",
"le monde"
Hope that helps...
Jeremy Kimball
|
|
|
|
|
I don't think that boxing takes place on strings, does it? Forgive me if I'm being dumb, as I have way more experience in Java than in .NET, but I believe that all strings are objects, aren't they? Class String extends/inherits from Object, not ValueType.
Also, the relative performance hit of using an ArrayList is not so minor in this case. I think that people should always program with performance in mind. Still, it's always nice to show people how to do things in different ways.
Regards,
Jeff Varszegi
|
|
|
|
|
Can any body guide me how to input password using VS.NET setup project, what i have seen is that there are text boxes which can take input but if i want to hide the text enterd in a password field i have no option. Presently what i am doing is that i have made a separate windows installer component which displays a modal dialog to input password, but it clearly seems something plugged into the setup and doesn't look like a part of setup when setup is run.
waiting for ur reply.
|
|
|
|
|
Can any body guide me how to input password using VS.NET setup project, what i have seen is that there are text boxes which can take input but if i want to hide the text enterd in a password field i have no option. Presently what i am doing is that i have made a separate windows installer component which displays a modal dialog to input password, but it clearly seems something plugged into the setup and doesn't look like a part of setup when setup is run.
waiting for ur reply.
|
|
|
|
|
The VS.NET setup project can't really be modified from what it supports. It's very basic. You should look into something like Wise Solutions for a real MSI development environment.
You could, however, add a new form (VS.NET has a fix number of fixed-layout forms) with a single text box then use a binary CustomAction to verify the password (almost like you are now) before proceding.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a Form.
Within the form's class, I have a method TestConnection which tries to establish a connection to a database, and returns a bool.
I invoke this method in the Form_Load method.
With regard to what TestConnection returned, I present the user with a messagebox asking whether to try again or not.
Since TestConnection takes a long time, I want to thread it, and once it completes, i want to check the returned bool and proceed.
What is the best way of threading it?
|
|
|
|
|
I'd do something like this:
public class MyThingy {
private bool testConnectionComplete = false;
private bool testConnectionResult = false;
....
public override void Form_Load(...) {
Thread tcStart = new Thread(new ThreadStart(this.TestConnection));
tcStart.Start();
Thread tcMonitor = new Thread(new ThreadStart(this.CheckTestConnection));
tcMonitor.Start();
}
public void TestConnection() {
this.testConnectionResult = WhateverYourResultIs;
this.testConnectionComplete = true;
}
public void CheckTestConnection() {
while( this.testConnectionComplete == false ) {
}
}
}
Of course, there may be better ways...
Jeremy Kimball
|
|
|
|
|
Do anyone know how to get back from the client the values of a data grid when columns have been added dinamically?
I noticed that if the AutoGenerateColumns flag is set to true and a dataset is binded to the DataGrid, postbacks include all the cells, even when the user changed values. This allows to add editing capabilities by traping the Update and Edit events.
However, if the columns are added dinamically (let's say template columns need to be used), no columns appear on the postback. See code below.
Notice that this part of the code
// BoundColumn pDBColumn = new BoundColumn();
// pDBColumn.DataField = "ARTIST";
// pDBColumn.HeaderText = "ARTIST2";
// DataGrid1.Columns.Add (pDBColumn);
adds a column dinamically. The column gets added to the response, but is missing on the client's request.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TemplateColumns
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label LblDebug;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
DataGridBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGridBind()
{
// BoundColumn pDBColumn = new BoundColumn();
// pDBColumn.DataField = "ARTIST";
// pDBColumn.HeaderText = "ARTIST2";
// DataGrid1.Columns.Add (pDBColumn);
// Simple bind to a TextBox control
if (Session["TheDataset"] == null)
{
DataSet pDS0 = new DataSet("EmployeesDataSet");
pDS0.ReadXml(@"c:\cd_catalog.xml");
Session["TheDataset"] = pDS0;
}
DataSet pDS = Session["TheDataset"] as DataSet;
DataGrid1.DataSource = pDS;
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.SelectedIndex = e.Item.DataSetIndex;
DataGrid1.EditItemIndex = DataGrid1.SelectedIndex;
this.LblDebug.Text = "Cells on DataGrid1_EditCommand: " + e.Item.Cells.Count.ToString();
DataGridBind();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.LblDebug.Text = "Cells on DataGrid1_UpdateCommand: " + e.Item.Cells.Count.ToString();
DataGridBind();
}
}
}
|
|
|
|
|
Can't quite get this right. I have:
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct MIDIHDR <br />
{<br />
[MarshalAs(UnmanagedType.LPStr)]<br />
public String Data;<br />
public uint Length;<br />
public uint RecBytes;<br />
public uint User;<br />
public uint Flags;<br />
public uint Next;<br />
public uint reserve;<br />
public uint Offset;<br />
public uint Reserved;<br />
}<br />
I am having problems getting the right MIDIHDR.data value, I think. I am building the data as follows:
I am building the string with a StringBuilder object.
I StringBuilder.Append() anywhere from 4 to 16 bytes.
I set MIDIHDR.data = StringBuilder.ToString() and
MIDIHDR.Length = StringBuilder.Length
When I test it by sending the MIDIHDR to a midiOutLongMsg call, I have gotten either no sound, or the same, wrong note, no matter what string I send.
example bytes {153, 41, 127, 0}
StringBuilder.ToString() outputs "153411270"
with a length of 9
What i believe this is doing is converting the byte with a value of 153 to a string of length 3 ("153"). Is there a way to build this string as just the 4 bytes? Can I, for example, cast the byte to char before appending to the string? Am I gonna have problems with the unicode/ansi conversion in the string and it's length as its size in the struct??? Or is the marshalling of the struct really taking care of all this and I just have an error elsewhere?
( I may not understand the proper way to use midiOutLongMsg() to send multiple ShortMsg's simultaneously...)
I was making headway with marshalling/interop and have been successful with everything but this. I have used the same byte data to successfully make calls to midiOutShortMsg. The bytes are actually stored in a struct of 4 bytes coerced into a union as an int. So it would be neat if I could just build the string using this int value to represent the 4 bytes, but for now I just wanna get it to work.
i am going to keep playing and researching, but I thought I'd stick the question here to see if I get a nibble.
Any help or insight would be greatly appreciated!
Thanks!
Tym!
Make love, not chocolate chip cookies with nuts.
At least make the cookies without nuts for crying out loud.
|
|
|
|
|
It's too damned early for me to really play with this too much, but my gut is telling me you should be using a byte array (byte[]) rather than a String/StringBuilder. Reason being that the LPSTR in the MIDIHDR is really a char* (read:byte array). Have you taken a stab at using byte arrays yet? You may not even need the MarshalAs attribute in that case...not sure.
Jeremy Kimball
|
|
|
|
|
Thanks for the advice. I was leaning that way, I got as far as using a byte array, but still using the marshalling attribute, which gave me a runtime error.
I think you will prove to be right, it makes sense.
Thanks again, I'll let ya know if it works when I get a chance to try it...
Tym!
|
|
|
|
|
Still can't get it to work...
I have tried combinations of :
byte[]
char[]
String
StringBuilder
no MarshalAs
MarshalAs LPStr, ByValTStr
but I get the following error each time except when building the buffer with a StringBuilder and declaring data as a string, don't need any marshalling:
MIDIHDR can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
I'm thinking I just need build the string differently, so I'm gonna see what I can find on StringBuilder and hope it gets me somewhere.
Thanks!
|
|
|
|