|
The former allows you to determine, at runtime, the object to be instantiated, while the latter requires that you know that information at design time.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Hello........
I have a problem of printing High resolution image to a spesific sized pages.
I want it to fit in the page.After scaling down the image based on destination sizes(paper sizes),
I am able to fit the image to a page but the quality of the image is not good.
Is there any solution for this????
|
|
|
|
|
Determine the resolution of the printout beforehand, calculate the number of pixels wide and tall, then resize the image using a custom resizing technique (there are quite a few out there). Some sharpen, some blur, some average pixels, some just take the nearest pixel. If you resize the image so it prints out in the native resolution of the printer, then it won't have to do the shoddy resizing (probably nearest pixel) and you'll get the type of resizing you specifically code for.
|
|
|
|
|
Hi All,
Can anyone tell me how can I have a multicolor string in a single cell of a datagridview.
For example " 000 0000 0000000 0000000 0000000000", now I want the four consecutive zeros "0000" in red and rest in black. Is it possible to do that.
Thanks and Regards
Akshay
|
|
|
|
|
Hi,
You need to override the paint method for the cell object. Cells that contain just text are instances of DataGridViewTextBoxCell Class, so override that. Below is my attempt at a new class with over-ridden paint method. The draw method also only draws what will fit in cell so there will be no overlapping of data between cells. I have tried to make it as reusable as possible so you can define what colour you wish to change to and the number of consecutive numbers that should have colour changed. I also include code I used to test the class out and a couple of screenshots showing it working.
public class MultiColourDataGridViewTextBoxCell : DataGridViewTextBoxCell
{
public MultiColourDataGridViewTextBoxCell():base()
{
}
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
int fontSize = 9;
Brush textBrush = Brushes.Green;
Font font = new Font(FontFamily.GenericSansSerif,fontSize,FontStyle.Regular);
String stringPrint = (String)formattedValue;
graphics.FillRectangles(Brushes.White,new Rectangle[]{cellBounds});
StringPrintInfo[] stringPrintInfo = GetConsectiveNumbers(4, stringPrint, Brushes.Black, Brushes.Red);
PrintConsectiveNumbers(stringPrintInfo,graphics, font,textBrush,cellBounds,StringFormat.GenericDefault);
this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
}
public StringPrintInfo[] GetConsectiveNumbers(int numberConsecutive, String input, Brush bOriginal, Brush bConsecutive)
{
List<StringPrintInfo> formatInformation = new List<StringPrintInfo>();
int inputCount = 0;
StringPrintInfo tmpStrPrntInfo;
String regExp = "\\b[0-9]{4}\\b";
Regex exp = new Regex(regExp);
foreach (Match match in exp.Matches(input))
{
if (inputCount < match.Index)
{
tmpStrPrntInfo = new StringPrintInfo();
String strTmp = input.Substring(0, match.Index);
tmpStrPrntInfo.str = strTmp;
tmpStrPrntInfo.brush = bOriginal;
inputCount = match.Index;
formatInformation.Add(tmpStrPrntInfo);
}
tmpStrPrntInfo = new StringPrintInfo();
tmpStrPrntInfo.str = match.Value;
tmpStrPrntInfo.brush = bConsecutive;
inputCount = match.Index + match.Length;
formatInformation.Add(tmpStrPrntInfo);
}
if (inputCount < input.Length)
{
tmpStrPrntInfo = new StringPrintInfo();
String strTmp = input.Substring(inputCount);
tmpStrPrntInfo.str = strTmp;
tmpStrPrntInfo.brush = bOriginal;
inputCount = input.Length;
formatInformation.Add(tmpStrPrntInfo);
}
return formatInformation.ToArray();
}
public void PrintConsectiveNumbers(StringPrintInfo[] toPrint,Graphics graphics, Font font ,Brush textBrush,Rectangle cellBounds, StringFormat stringFormat)
{
float xOffset = 0;
for(int i = 0;i<toPrint.Length;i++)
{
if (i > 0)
{
SizeF stringSize = graphics.MeasureString(toPrint[i-1].str, font);
xOffset += stringSize.Width;
}
if (cellBounds.X+ xOffset + graphics.MeasureString(toPrint[i].str, font).Width > cellBounds.X + cellBounds.Width)
{
string cutDown = toPrint[i].str;
for (int j = cutDown.Length; j > 0; j--)
{
cutDown = cutDown.Substring(0, j);
if (cellBounds.X + xOffset + graphics.MeasureString(cutDown, font).Width <= cellBounds.X + cellBounds.Width)
{
graphics.DrawString(cutDown, font, toPrint[i].brush, cellBounds.X + xOffset, cellBounds.Y, stringFormat);
break;
}
}
}
else
{
graphics.DrawString(toPrint[i].str, font, toPrint[i].brush, cellBounds.X + xOffset, cellBounds.Y, stringFormat);
}
}
}
public struct StringPrintInfo
{
public String str;
public Brush brush;
}
}
DataSet dataSet = new DataSet();
DataTable dStable = new DataTable();
DataColumn dSCol1 = new DataColumn("name", typeof(string));
DataColumn dSCol2 = new DataColumn("value", typeof(string));
DataRow rTemp;
DataGridViewColumnCollection dGVColumnCollection;
DataGridViewColumn dGVColumn1 = new DataGridViewColumn();
DataGridViewColumn dGVColumn2 = new DataGridViewColumn();
public partial class Form1 : Form
{
DataSet dataSet = new DataSet();
DataTable dStable = new DataTable();
DataColumn dSCol1 = new DataColumn("name", typeof(string));
DataColumn dSCol2 = new DataColumn("value", typeof(string));
DataRow rTemp;
DataGridViewColumnCollection dGVColumnCollection;
DataGridViewColumn dGVColumn1 = new DataGridViewColumn();
DataGridViewColumn dGVColumn2 = new DataGridViewColumn();
public Form1()
{
InitializeComponent();
dStable.TableName = "sample";
dStable.Columns.Add(dSCol1);
dStable.Columns.Add(dSCol2);
rTemp = dStable.NewRow();
rTemp.ItemArray = new object[]{"bill", " 000 0000 0000000 0000000 0000000000"};
dStable.Rows.Add(rTemp);
rTemp = dStable.NewRow();
rTemp.ItemArray = new object[]{"ted", " 111 1111 1111111 1111111 1111111111"};
dStable.Rows.Add(rTemp);
rTemp = dStable.NewRow();
rTemp.ItemArray = new object[] { "john", " 222 2222 2222222 2222222 2222222222" };
dStable.Rows.Add(rTemp);
dataSet.Tables.Add(dStable);
dGVColumnCollection = dataGridView1.Columns;
dGVColumnCollection.Add("col1", "Name");
dGVColumnCollection.Add("col2", "Value");
dGVColumn1 = dGVColumnCollection[0];
dGVColumn2 = dGVColumnCollection[1];
foreach(DataRow row in dataSet.Tables[0].Rows)
{
DataGridViewRow dGVRow = new DataGridViewRow();
DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();
MultiColourDataGridViewTextBoxCell textCel2 = new MultiColourDataGridViewTextBoxCell();
textCell.Value = row.ItemArray[0];
textCel2.Value = row.ItemArray[1];
dGVRow.Cells.Add(textCell);
dGVRow.Cells.Add(textCel2);
dataGridView1.Rows.Add(dGVRow);
}
}
}
http://img2.pict.com/b4/07/ad/2401377/0/gridcellcolour1.jpg
http://img2.pict.com/91/13/8d/2401376/0/gridcellcolour2.jpg
modified on Tuesday, January 5, 2010 9:17 PM
|
|
|
|
|
Mind blowing..... thanks a lot .....
|
|
|
|
|
Hi All,
I am using VS 2008, 3.5 and am trying to add drag and drop functionality to the treeview. However, the allowdrop property is non existent on the treeview control.
I am baffled as to why this is the case.
Even when Ive instantiated the control it is neither existant nor does it appear behind the server control. help is much appreciated.
|
|
|
|
|
Uhm what treeview control are you using, the standard MS one (I presume you are using winforms) certainly has all the drag drop functionality.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
using VS 2008, asp.net 3.5 sp1. From what I am gathering the treeview control for webcontrols has no capacity for drag and drop, which exists for the winforms.
|
|
|
|
|
Have you ever seen drag and drop implemented on a web form? I think I have but VERY rarely. I notice the web control is categorised as a navigation control rather than a normal or data control, I would expect it to have different functionality.
I have a requirement for a web treeview (with D&D) coming up so I will be interested in your results.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes indeed , its quite rare from what I have seen thus far. Web control are very different to winforms controls indeed. I will let you know how I go, though time is something I dont really have in relation to using this for a project...so i might even neglect this all together and tinker with something else.
|
|
|
|
|
how to make lots of bmp files into one "movie" file
I have a lot of still images from a simulation, I need my application to take all those images and make them into 1 "movie" file, container format.
Can anyone give me a good idea on how to do that in VS8.
thorthebrave
|
|
|
|
|
Maybe the best is to create a fake wakecam...
This webcam will read files (BMP) or other formats and send it to the pin.
This can be easly done, and then use a regular tool in order to record your stream.
|
|
|
|
|
Can you elaborate on that. I have no clue what you are talking about.
|
|
|
|
|
Hi All,
I want to design a sliding forms in windows mobile environment using C#.NET, I know that this can be done using the Location property of the form, but unfortunately, when I change the property to be negative on the X - axis, once I call the resumelayout function, it will returned back again to the original location which is the point (0,0).
do u have any ideas or any workaround for this problem.
Regards
|
|
|
|
|
I have a dictionary call timeDate. where DriveDT is an object.
static Dictionary<string, DriveDT> timeDate = new Dictionary<string, DriveDT>();
I want to remove the value from the dictionary, the line im using is in the section else //unload
But the line isnt working.
timeDate.Remove(key);
private static void extractSE(string filePath)
{
StreamReader textIn = new StreamReader(filePath);
do
{
string text = textIn.ReadLine();
bool mail = text.Contains("Mail");
if(!mail)
{
if ((text != ""))
{
int indexofTO = text.IndexOf("to");
int indexofSLOT = text.IndexOf("Slot");
if (indexofSLOT < indexofTO)
{
int indexofInfo = text.IndexOf("Info");
string dtTxt = text.Substring(0, (indexofInfo - 1));
DateTime dt = DateTime.Parse(dtTxt);
string data = text.Substring(indexofInfo);
string key = text.Substring(indexofSLOT, (indexofTO - indexofSLOT - 1));
timeDate.Add(key, new DriveDT(dt, data));
}
else
{
string key = text.Substring((indexofTO + 2));
timeDate.Remove(key);
}
}
}
}
while (!textIn.EndOfStream);
}
modified on Monday, January 4, 2010 11:30 AM
|
|
|
|
|
Paul Harsent wrote: the line isnt working
that is unclear.
PS: please use PRE tags (the "code block" widget), I'm not interested in unformatted code.
You can still edit the message.
|
|
|
|
|
I think what Luc means is: use the "code block" widget to presever your formatting on your original code. that would produce:
if(!mail)
{
if ((text != ""))
{
int indexofTO = text.IndexOf("to");
int indexofSLOT = text.IndexOf("Slot");
if (indexofSLOT < indexofTO)
{
...
}
}
} which I think you will agree is easier to read than:
if(!mail)
{
if ((text != ""))
{
int indexofTO = text.IndexOf("to");
int indexofSLOT = text.IndexOf("Slot");
if (indexofSLOT < indexofTO)
{
...
}
}
} Just putting the tags around your already posted code doesn't do that - try the "Preview" button when you add tags.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Done, thanks. didnt realise.
|
|
|
|
|
right (actually this is the left side)
|
|
|
|
|
Much better, thanks.
Dictionary.Remove() removes an entry based on a key object, not the value. Even when two strings have equal content, they probably are different strings (unless they are simple reference copies, or both got interned).
Not sure what the easy solution is, I seldom remove things from a Dictionary.
[EDIT]
No, that is not it. A simple experiment shows Dictionary.Remove uses the default Comparer, which for strings compares the content.
Are you sure indexofTO + 2 is correct? How about indexofTO + 3?
[/EDIT]
modified on Monday, January 4, 2010 11:55 AM
|
|
|
|
|
Have you run this through the debugger? I bet the key is an empty string (or worse). If it can't find the key to remove, what exactly do you expect Remove() to do?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
This line move media into a drive.
19/05/2009 10:53:40 Info Moved cartridge from Library 2 Slot 1 to Tape Drive 1
So I store the date time and the slot number(key) of when the media was moved into a drive, and when I see a removed media line, I used the date time from when it was moved out to show how long the media has been in.
I need to remove it from the dic because the media can be used again and I cant have duplicate keys.
FYI, there can be load of media being used at once, which I why I need to store this information.
An example of the data im reading in
19/05/2009 17:50:58 Info Moved cartridge from Library 2 Slot 4 to Tape Drive 1
19/05/2009 17:51:00 Info Moved cartridge from Library 2 Slot 8 to Tape Drive 2
19/05/2009 17:55:15 Info Moved cartridge from Library 2 Tape Drive 1 to Slot 4
19/05/2009 17:56:20 Info Moved cartridge from Library 2 Slot 1 to Tape Drive 1
19/05/2009 18:07:45 Info Moved cartridge from Library 2 Tape Drive 2 to Slot 8
19/05/2009 18:08:09 Info Moved cartridge from Library 2 Slot 7 to Tape Drive 2
20/05/2009 12:36:02 Info Moved cartridge from Library 2 Tape Drive 1 to Slot 1
20/05/2009 12:36:07 Info Moved cartridge from Library 2 Slot 6 to Tape Drive 1
20/05/2009 18:23:19 Info Moved cartridge from Library 2 Tape Drive 2 to Slot 7
|
|
|
|
|
So do any of the keys match the string you're building when you do your index math? That was my point.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
When I step through with the debugged. "Slot 1" is stored as the key in the dic and the on the loop that goes through to remove it the string key is also Slot 1.
|
|
|
|
|