|
Got it working - thanks.
Only problem is using the AddRange method - I get:
Argument '1': cannot convert from 'SparePartCollection' to 'System.Collections.Generic.IEnumerable<IStockItem>'
I can fix this by making the SparePartCollection : List<IStockItem> but that will be no use as I need the collection to be a List<SparePart>
(Obviously the same applies to ServiceToolCollection)
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I've managed to make it work by using the ConvertAll method but it seems messy!
items.AddRange(spares.ConvertAll(new Converter<SparePart, IStockItem>(SparePart.ToIStockItem)));
and in SparePart struct
public static IStockItem ToIStockItem(SparePart value)
{
return (IStockItem)value;
}
Is there a better way?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
/edit: my initial advice didn't work.
Looks like you really have to convert the entire collection. However, you can save the static method by using an anonymous method:
items.AddRange(collection.ConvertAll(new Converter<SparePart,IStockItem>(delegate(SparePart value) { return (IStockItem)value; })));
In 3.5 and the System.Linq namespace, you can also use this:
items.AddRange(collection.Cast<IStockItem>());
regards
modified on Saturday, August 2, 2008 11:35 AM
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: items.AddRange(collection.Cast<istockitem>());
Yay - good old Linq
Thanks for all your help.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I've adapted your code(s) to my real world code (more complex than the example I posted) and it's working superbly. Thanks very much - again. I wish there was a way I could vote 10 for your help with this!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi
I am drawing a rectangle using OnmouseClick(vector image)..how can i convert to meta file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnMouseClick(MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
g.DrawRectangle(new Pen(Color.Blue), new Rectangle(e.X, e.Y, 20, 40)); // How can i convert this vector in to a \\ meta file
base.OnMouseClick(e);
}
protected override void OnPaint(PaintEventArgs e)
{
//how to display the meatfile here
base.OnPaint(e);
}
}
}
Can anyone please explain this with source code.
Regards,
ALGATES
algates
|
|
|
|
|
It is very bad practice to paint on a form through a non-graphic event. (For assistance purposes, I am assuming a meta file is an image). The following is pseudocode (not syntactically accurate).
public Form:Form
{
bool isClickedPerformed=false;
public override OnMouseClick(...)
{
if(e.MouseButton==MouseButton.Right)
isClickedPerformed=true;
this.invalidate();
}
public override OnPaint(....)
{
if(isClickedPerformed)
e.graphics.drawimage(...follow paramters/usage based on either MSDN Documentation or Object Browser in VS IDE);
}
}
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Hi all,
How to find Content datatype in a String.
ex: String str="";
In above string accepting only numeric or only characters(string).
i.e: str = "3";
str ="abcdefgh";
I have to find content data type in 'str' variable i.e whether the assigned value is integer or string.
Please suggest me, how to find that.
Thanks in advance
sekhar
|
|
|
|
|
If you want to accept only a number, why not use an integer? You can always convert the integer to string. I'd be shocked if C# didn't have something like ToString().
|
|
|
|
|
int.TrypParse(string, out int) method. Some other ther types have the TryParse method too - all return a bool indicating whether it was successful and an out parameter which passes the value to a variable of the type you were checking for.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
you can use regex match to determine its content.
|
|
|
|
|
ThanQ for your response.
Could you please write code for that.
Regards
sekhar
|
|
|
|
|
sekhar.k wrote: Could you please write code for that.
I thought that this was a forum for programmers, not copy-pasters...
if (Regex.Match(str, "^\d+$").Success) ...
^ = start of string
\d = any digit
+ = one or more times
$ = end of string
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
This is my first code :
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();//display the interface to change font
this.Font= fontDialog1.Font;
}
and the result i get for chaning the font size to 14 is this :
After that, I change the code to this :
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();//display the interface to change font
btnTest.Font= fontDialog1.Font;
}
and this is what i get for changing the font size to 14 :
It seems that by using " this.Font " causes the form and the button to resize in proportion with the Font size of the button.
However, by using "btnTest.Font" causes only the font size of the button to change without making the form and button to resize in proportion with the font size of the button.
Can anyone please tell me why is that so ?
|
|
|
|
|
The difference is because the Form has its AutoScaleMode property set to Font (which I believe is the VS default for that property). So when you set the Form font size, it triggers an auto scale, but since the Button does not have an AutoScaleMode property, changing the font size does nothing.
For what it's worth, if you were using WPF, the button would have resized in both situations. So if you really want that resizing behavior and your requirements allow WPF, I would suggest switching. Otherwise, you may end up having to find some component that does it for you or write all the resizing code yourself.
|
|
|
|
|
Thanks alot! I experimented with the AutoScaleMode property and have a better understanding of the reason.
|
|
|
|
|
plz any one tale me how to add rular in toolbar what is the code for..
amitshan
|
|
|
|
|
Click this [^]
Hi this may help You i Suggest Google this u will find many
Happy programming
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
amitshan wrote: what is the code for..
Wow. Can't do your own code? Google on how to add a ruler to the toolbar, learn how to code it.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi all
I have a problem in counting/extracting matches from a URL string using Regex:
My URL looks like this:
www.website.com/LanguageName/BookName/filename.txt
I use the following code to extract Language name and Bookname:
Match bookMatch = Regex.Match(requestString, "/[^/]*/[^$]", RegexOptions.RightToLeft);<br />
BookInfo bookInfo = new BookInfo();<br />
if (bookMatch.Success)<br />
{ <br />
bookInfo.BookName = bookMatch.Groups[0].Value.Substring(1, bookMatch.Groups[0].Value.Length - 3);<br />
Match langMatch = bookMatch.NextMatch();<br />
if (langMatch.Success)
{<br />
bookInfo.Langauge = langMatch.Groups[0].Value.Substring(1, langMatch.Groups[0].Value.Length - 3); <br />
}<br />
<br />
}<br />
return bookInfo;
Now the code successfully extracts Bookname as it is rightmost in the expression, let us assume that we have the following URL:
www.website.com/LanguageName/BookName/filename.txt
bookMatch will match "/BookName/f", so I remove the 1st one and last two characters to get the bookname correctly.
Now the langMatch doesn't catch the language in the string which should be "/LanguageName/B", it seems that this is happening becoz the 1st match (right to left) has ended at the slash "/" before the BookName, so the search for the next Match will begin on the "e" (last char) character of the LanguageName which will not result in a match.
So how to force the search for the next match to begin on the "/" between the "B" and the "e"?
Any ideas? thanks.
And ever has it been that love knows not its own depth until the hour of separation
Mohammad Gdeisat
|
|
|
|
|
Unfortunately I can't help you with this problem, but why don't you use the Uri class to extract the necessary parts of the URL?
You can use this code:
Uri url = new Uri(@"http://www.website.com/LanguageName/BookName/filename.txt");
string languageName = url.Segments[1];
string bookName = url.Segments[2];
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Excellent, I didn't know about this class
However, if anybody knows how to do it using a Regex then I would be glad to know
Thanks mate
And ever has it been that love knows not its own depth until the hour of separation
Mohammad Gdeisat
|
|
|
|
|
In your case this regex will work, but you have to carefully test it with other URLs:
[^/]/(?<LanguageName>[^/]+)/(?<BookName>[^/]+)/
And some code:
Regex regex = new Regex(@"[^/]/(?<LanguageName>[^/]+)/(?<BookName>[^/]+)/");
Match match = regex.Match(@"www.website.com/LanguageName/BookName/filename.txt");
if (match.Success)
{
string languageName = match.Groups["LanguageName"]);
string bookname = match.Groups["BookName"]);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
What you are looking for is the concept of a lookahead and lookbehind. This pattern should work:
(?<=/)[^/]*(?=/)(?<!$)
I would suggest looking at the documentation to fully understand how lookahead/behind expressions work. Here's a link to get started:MSDN
|
|
|
|
|
Hi, this is silly
How can i force the write in the next line/row?
No Picture Available
No Picture
Available
Thanks
|
|
|
|