|
|
Hi,
Do you know any safe and reliable approach to convert a VB.Net solution to C# one?(Framework 3.5)
Best wishes
|
|
|
|
|
mehrdadc48 wrote: safe and reliable approach
I'm sure there are plenty of tools available if you do a search on the internet.
IMO, the safest and most reliable to do this would probably be to do it yourself. Sorry.
|
|
|
|
|
|
Any of the commercial utilities will do this well - VB to C# and C# to VB conversion are both very established. Also, C# and VB(.NET) both use the same framework, so that's an entire level of conversion that you don't have to worry about.
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
Hi there. I'm continuing to learn c# but moved on to the .net 4 compact framework. I have this piece of code i am using in a project. All though it does what i want it too, it feels to clunky and no need for multiple methods. I just don't know how to optimize it.
I am trying to get it to do everything in the responsehandler, without the need for 3 of the same methods. It means my code wont be clunky and unoptimized and i believe all the feeds with display at once and not at different times.
but fyi its using system.xml and system.servicemodel.syndication --typo
namespace NewsTap
{
public partial class NewsFeed : PhoneApplicationPage
{
object _selectedItem;
public NewsFeed()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.Portrait;
Loaded += new RoutedEventHandler(MainPage_Loaded);
PageTransitionList.Completed += new EventHandler(PageTransitionList_Completed);
string bbc = "http://www.pchelpforum.com/external.php";
string dailyMail = "http://www.dailymail.co.uk/home/index.rss";
string guardian = "http://www.guardian.co.uk/tv-and-radio/rss";
HttpWebRequest bbcRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(bbc));
bbcRequest.BeginGetResponse(new AsyncCallback(ResponseHandler), bbcRequest);
HttpWebRequest DailyMailRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(dailyMail));
DailyMailRequest.BeginGetResponse(new AsyncCallback(ResponseHandlerdaily), DailyMailRequest);
HttpWebRequest GuardianRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(guardian));
GuardianRequest.BeginGetResponse(new AsyncCallback(ResponseHandlerguardian), GuardianRequest);
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ResetPageTransitionList.Begin();
}
#region getting feed
private void ListBbc_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_selectedItem = (sender as ListBox).SelectedItem;
PageTransitionList.Begin();
}
private void ListDailyMail_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_selectedItem = (sender as ListBox).SelectedItem;
PageTransitionList.Begin();
}
private void ListGuardian_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_selectedItem = (sender as ListBox).SelectedItem;
PageTransitionList.Begin();
}
private void PageTransitionList_Completed(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/DetailsPage.xaml", UriKind.Relative));
FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
root.DataContext = _selectedItem;
}
private void ResponseHandler(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
if (response.StatusCode == HttpStatusCode.OK)
{
XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed newFeed = SyndicationFeed.Load(reader);
ListBbc.Dispatcher.BeginInvoke(delegate
{
ListBbc.ItemsSource = newFeed.Items;
});
}
}
private void ResponseHandlerdaily(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
if (response.StatusCode == HttpStatusCode.OK)
{
XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed newFeed = SyndicationFeed.Load(reader);
ListDailyMail.Dispatcher.BeginInvoke(delegate
{
ListDailyMail.ItemsSource = newFeed.Items;
});
}
}
private void ResponseHandlerguardian(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
if (response.StatusCode == HttpStatusCode.OK)
{
XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed newFeed = SyndicationFeed.Load(reader);
ListGuardian.Dispatcher.BeginInvoke(delegate
{
ListGuardian.ItemsSource = newFeed.Items;
});
}
}
#endregion
}
}
Any help would be great. Thanks in advance to any repliers,
malcomhfc
|
|
|
|
|
Well, lets see what's in common between your three methods. Everything is the same except for the address you read and which ItemsControl you are filling. If you combined those two things into a separate class, you could simplify the form code.
The class would look something like this:
public class FeedReader
{
FeedReader(string address, ItemsControl target)
{
_address = address;
_target = target;
}
private string _address;
private ItemsControl _target;
public void LoadFeed()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(_address));
request.BeginGetResponse(new AsyncCallback(ResponseHandler), request);
}
private void ResponseHandler(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
if (response.StatusCode == HttpStatusCode.OK)
{
XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed newFeed = SyndicationFeed.Load(reader);
_target.Dispatcher.BeginInvoke(delegate
{
_target.ItemsSource = newFeed.Items;
});
}
}
}
And the calling code could then be:
public NewsFeed()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.Portrait;
Loaded += new RoutedEventHandler(MainPage_Loaded);
PageTransitionList.Completed += new EventHandler(PageTransitionList_Completed);
FeedReader bbc = new FeedReader("http://www.pchelpforum.com/external.php", ListBbc);
FeedReader dailyMail = new FeedReader("http://www.dailymail.co.uk/home/index.rss", ListDailyMail);
FeedReader guardian = new FeedReader("http://www.guardian.co.uk/tv-and-radio/rss", ListGuardian);
bbc.LoadFeed();
dailyMail.LoadFeed();
guardian.LoadFeed();
}
|
|
|
|
|
Ah great modified it to my liking. Much shorter and more readable
Thank you a lot. Sorry for my late reply was back to college this week.
|
|
|
|
|
hey all,
I've implemented progressbar in backgroundWorker...
the progressbar changes on backgroundWorker_ProgressChanged
now i want to upgrade the progress bar, and to add it the progress percent display
that's what i did so far :
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
...
progressBar1.Value = e.ProgressPercentage;
progressBar1.Refresh();
int percent = (int)(((double)progressBar1.Value / (double)progressBar1.Maximum) * 100);
progressBar1.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));
}
but the problem is , each progress bar change, the percent text is blinking... (i hope you understand what i meant to)
any idea how to solve that ?
thanks
modified on Sunday, April 18, 2010 7:05 AM
|
|
|
|
|
Hi,
several comments:
1.
you should turn your progress bar (or the container holding it) into a double-buffered one; there is a property for that.
2.
you should not redo the progress bar stuff if the value hasn't changed, so put it all in a if (progressBar1.Value != e.ProgressPercentage) {...}
3.
you should dispose of all objects you created but no longer need whenever they offer a Dispose() method. Here it is the Graphics you ordered, and the Font (which you could store as a class member and reuse).
[ADDED]
There are several related articles here on CodeProject; here is just one: Extended ProgressBar[^]
[/ADDED]
|
|
|
|
|
solution #1, what does it do ?
solution #2,
why progress bar should not be changed ? each time the backgroundWorker_ProgressChanged executed, the value is changed...
solution #3,
to store font as a class member and reuse it, it saves object creation time during the runtime ?
actually I've solved it differently (and it works ok)
i just added Thread.sleep(150); before the method ends...
modified on Sunday, April 18, 2010 7:42 AM
ok, my solution doesn't help much, the percent text doesn't blink anymore, but the thread.sleep stuck the whole gui...
but non of your tips haven't helped me either...
|
|
|
|
|
DoubleBuffered is the name of a property. That will do the trick. Set it to true.
|
|
|
|
|
already did it... no change
|
|
|
|
|
I suggest doing the following:
1. Extend the ProgressBar class and Set a property for DisplayText.
2. Everytime the displaytext is changed, you can invalidate the progressbar.
3. Draw the progressbar by overriding the onpaint event.
4. From the background worker, only update the progressbar's DisplayText property.
|
|
|
|
|
can you please share with me what you've done ?
I'm new with all the graphic change stuff, therefor your example will help/teach me ...
thanks in advance
|
|
|
|
|
I overlooked the complete answer provided by Luc.
Luc has provided a link to a custom progress bar. That would be the best thing to do for now.
<added>
What I have done is in my software. And it was basically to create various colored custom bars. It was similar to the link that Luc has provided.
|
|
|
|
|
another strange issue,
after the percent counting is finishes, the percent string disappears just after the progressBar.value got to it maximum value.
that's the code
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
...
progressBar1.Value = e.ProgressPercentage;
progressBar1.Refresh();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
updateText();
}
private void updateText()
{
int percent = (int)(((double)(progressBar1.Value - progressBar1.Minimum) /
(double)(progressBar1.Maximum - progressBar1.Minimum)) * 100);
using (Graphics gr = progressBar1.CreateGraphics())
{
gr.DrawString(percent.ToString() + "%",font, Brushes.Black,
new PointF(progressBar1.Width / 2 - (gr.MeasureString(percent.ToString() + "%",
SystemFonts.DefaultFont).Width / 2.0F),
progressBar1.Height / 2 - (gr.MeasureString(percent.ToString() + "%",
SystemFonts.DefaultFont).Height / 2.0F)));
}
Thread.Sleep(100);
}
in this code, the percent string disappears...
but i notcide that if i add another progress bar (progressBar2) and at the end (in backgroundWorker_RunWorkerCompleted ) i add progressBar2.Value = X; , the percent in progressBar1 (the percent remain on his place after the maximal value was reached)
what can it be ? and how can i solve it ?
thanks
|
|
|
|
|
|
Emran Hussain wrote: I did not find any section dedicated to Visual Studio
On the left hand side of the screen, under "General Discussions", second forum below "The Lounge": "Visual Studio"
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thank you for showing me the section. I have posted my question there and going to delete from here.
|
|
|
|
|
Hi,
I am wondering, I have developed many Windows and Web Form Controls in .NET 2.0. Now, if I want to develop application in .NET 4.0 in Visual Studio 2010, will I be able to use them without any modification ?
|
|
|
|
|
In all probability, you should be able to do so.
However, a few of the methods you may have used in 2.0 may be deprecated.
|
|
|
|
|
Hello. I wrote a simple select area, but its working slow when form is maximized, who knows some alternative fast methods for this
here is my code
sry for bad english
public partial class Form1 : Form
{
bool canResize;
int mX, mY;
Rectangle rect = new Rectangle();
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Brushes.Purple, 2), rect);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
canResize = true;
mX = e.X; mY = e.Y;
rect.Location = new Point(mX, mY);
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
canResize = false;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (canResize)
{
if (mX < e.X)
{
rect.X = mX;
rect.Width = e.X - mX;
}
else
{
rect.X = e.X;
rect.Width = mX - e.X;
}
if (mY < e.Y)
{
rect.Y = mY;
rect.Height = e.Y - mY;
}
else
{
rect.Y = e.Y;
rect.Height = mY - e.Y;
}
this.Invalidate();
}
}
}
|
|
|
|
|
Hi,
I suggest you don't create new pens all the time; create one and keep it as a class member instead.
|
|
|
|
|
it did not help
anyway thx
modified on Sunday, April 18, 2010 5:41 AM
|
|
|
|
|