|
Richard thank you for the feedback and you’re correct, I was just giving feedback on what worked for me.
Thank you and wish you a lovely evening.
How do we close this post as solved as you have helped me with my code.
|
|
|
|
|
|
First of all, that is not a special red line, nor is that a progress bar. That is merely a horizontal line, that you can draw—or even better you can configure a border for the bottom or top control to be shown as a red solid line.
Border Class (System.Windows.Controls) | Microsoft Docs
Secondly, this is a ProgressBar, that control in the picture is not. That control is known as a Slider, that lets your users slide across a range of values.
Quote: What should I install in the visual studio ? That depends on what you already have. Most of the controls are framework-based, such as WinForms or WPF. You need to download the specific framework and then develop the app in that framework.
There are some UI control providers too, such as Telerik, Infragistics, etc. that can help you author the UI using the controls that may not be available in the framework. But this depends on your use case, what framework do you have?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I found it. It's control TrackBar and control pannel
|
|
|
|
|
Hi there!
I'm playing around with graphics in C#. I've managed to create a simple application using graphic object to draw some lines and scroling text to a pictureBox. Now I've decided to put my code into a Class (like for further re-use... and mostly for the learning purposes!), but I'm stuck on how to get the graphics back from Class to my pictureBox. The problem (I think!) lies as I'm doing all my drawings in the timer_tick event...
Here's the current code I'm using...
CLASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
namespace Osciloscope
{
public class Osciloscope
{
int SCOPE_WIDTH, SCOPE_HEIGHT;
int SCOPE_HORIZONTAL_CENTER, SCOPE_VERTICAL_CENTER;
int SCAN_POINT_X;
int SCAN_POINT_Y;
int SCAN_POINT_X_NEW;
int SCAN_POINT_Y_NEW;
int TIMER_INTERVAL;
Bitmap _Image;
Graphics g;
Pen p;
public Osciloscope(PictureBox picture, bool Run, int Interval)
{
SCOPE_HEIGHT = picture.Height;
SCOPE_WIDTH = picture.Width;
TIMER_INTERVAL = Interval;
SCOPE_HORIZONTAL_CENTER = SCOPE_WIDTH / 2;
SCOPE_VERTICAL_CENTER = SCOPE_HEIGHT / 2;
SCAN_POINT_X = 1;
SCAN_POINT_Y = SCOPE_VERTICAL_CENTER;
_Image= new Bitmap(SCOPE_HEIGHT, SCOPE_WIDTH);
Timer t = new Timer();
t.Tick += new EventHandler(t_Tick);
if (Run)
{
t.Enabled = true;
t.Interval = TIMER_INTERVAL;
t.Start();
}
else
{
t.Stop();
}
}
void t_Tick(object sender, EventArgs e)
{
g = Graphics.FromImage(_Image);
p = new Pen(Color.Green, 2f);
SCAN_POINT_X_NEW = SCAN_POINT_X + 1;
SCAN_POINT_Y_NEW = SCAN_POINT_Y;
g.DrawLine(p, SCAN_POINT_X, SCAN_POINT_Y, SCAN_POINT_X_NEW, SCAN_POINT_Y_NEW);
p.Dispose();
g.Dispose();
SCAN_POINT_X++;
if(SCAN_POINT_X==SCOPE_WIDTH)
{
SCAN_POINT_X = 1;
}
}
public Image DrawGraph
{
get
{
return _Image;
}
}
}
}
... and the form itself...
namespace Osciloscope
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
Osciloscope Osciloscope;
private void FrmMain_Load(object sender, EventArgs e)
{
Osciloscope = new Osciloscope(Scope, true, 5);
Scope.Image= Osciloscope.DrawGraph;
}
}
}
As I said: I just can't figure out how to get the drawing into the pictureBox... (Scope is the name of the pictureBox!)
Any help woul be highly appreciated!
Regards!
// EDIT: There's no scroling text in current code as I left it out for simplicity...
|
|
|
|
|
The usual way is to implement a drawing method in the class that will draw its content. You can then pass the details of the surface (x,y, width and height etc.) to the method and let it do the work.
|
|
|
|
|
Thanks!
Well, that's the problem I'm having... don't really know how to do it! (As I've mentioned before, I'm a novice trying to learn things the hard way...
I grabbed and sniffed various code samples here on CP and mollested Google for quite some time but to no avail...
Would you be so kind to just point me in the right direction?
Regards!
|
|
|
|
|
Create a method in the class that takes a reference (or maybe more than one) as input parameter. These references tell the class where to draw its contents, so one of the references must be the PictureBox, or whatever control surface you are drawing onto. The method then does exactly what you have already coded in your existing t_tick method. You already have all the code, you just need to move it into the relevant places.
|
|
|
|
|
Thank you 1M times!
I've got it working (well... sort of...). It works BUT it works SLOWLY and it draws only 2/3 of the width of the pictureBox! Any idea?
Here's the code so far...
CLASS:
namespace Osciloscope
{
public class Osciloscope
{
int SCOPE_WIDTH, SCOPE_HEIGHT;
int SCOPE_HORIZONTAL_CENTER, SCOPE_VERTICAL_CENTER;
int SCAN_POINT_X;
int SCAN_POINT_Y;
int SCAN_POINT_X_NEW;
int SCAN_POINT_Y_NEW;
int TIMER_INTERVAL;
Bitmap _Image;
Graphics g;
Pen p;
public Osciloscope(PictureBox picture, bool Run, int Interval)
{
SCOPE_HEIGHT = picture.Height;
SCOPE_WIDTH = picture.Width;
TIMER_INTERVAL = Interval;
SCOPE_HORIZONTAL_CENTER = SCOPE_WIDTH / 2;
SCOPE_VERTICAL_CENTER = SCOPE_HEIGHT / 2;
SCAN_POINT_X = 1;
SCAN_POINT_Y = SCOPE_VERTICAL_CENTER;
_Image = new Bitmap(SCOPE_HEIGHT, SCOPE_WIDTH);
Timer t = new Timer();
t.Tick += new EventHandler(t_Tick);
if (Run)
{
t.Enabled = true;
t.Interval = TIMER_INTERVAL;
t.Start();
}
else
{
t.Stop();
}
}
void t_Tick(object sender, EventArgs e)
{
DrawGraph();
}
public Bitmap DrawGraph()
{
g = Graphics.FromImage(_Image);
p = new Pen(Color.Green, 1f);
SCAN_POINT_Y_NEW =(int) Math.Sin(SCAN_POINT_X);
g.DrawLine(p, SCAN_POINT_X, SCAN_POINT_Y, SCAN_POINT_X_NEW, SCAN_POINT_Y_NEW);
p.Dispose();
g.Dispose();
SCAN_POINT_X_NEW = SCAN_POINT_X;
SCAN_POINT_X=SCAN_POINT_X+10;
if (SCAN_POINT_X == SCOPE_WIDTH)
{
SCAN_POINT_X = 1;
}
return _Image;
}
}
}
And Form...
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
Osciloscope Osciloscope;
private void FrmMain_Load(object sender, EventArgs e)
{
Osciloscope = new Osciloscope(Scope, true, 1);
this.Text = Scope.Width.ToString();
Scope.Invalidate();
}
private void Scope_Paint(object sender, PaintEventArgs e)
{
Scope.Image = Osciloscope.DrawGraph();
}
}
|
|
|
|
|
You call DrawGraph from your main form and then again from your timer event which is not the way to do it. The DrawGraph method should just draw all the points that belong to the graph. You should probably have a separate method that collects the points based on some external occurrence.
|
|
|
|
|
Yes, I know... silly of me... I was trying to grasp how things work and got it all messed up at the end I've downloaded a sample from (How to create a simple Radar in CSharp using Visual Studi[^]) that demonstrates basic graphic (simple radar).
The original idea was to make things work from separate class - just for the sake of learning how stuff works and how it's done. At the end I wasn't able to get it to work - the problem was that all of the drawings was done in timer and I just couldn't get it to update the pictureBox...
Anyway, thanks for reply!
Regards!
|
|
|
|
|
|
Could be 32/64 bit issue if the driver is not recognised.
|
|
|
|
|
I installed the 64 bit version
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The error message suggests that whichever version you installed, it is looking for the other one. Either that or the installation did not work for some reason.
|
|
|
|
|
The message doesn't suggest that at all. It says it can't find it.
FYI. I tried installing both versions. Same result.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Sorry, mis-read the message. I have used both Jet and ACE and never faced this problem.
|
|
|
|
|
Maybe I should try Jet
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Kevin Marois wrote: Maybe I should try Jet If MS jet is not installed, the error should say
"Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine ".
Install the MS-access runtime, the 32 bit version. It would install all the drivers you need Check your app to be 32-bit, not any-CPU.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I reinstalled the 32 bit version and change the Platform to Any CPU and that did it.
Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
If your Access drivers are 32-bit, your app must also be 32-bit. Because you're using the Access drivers, I'd switch the compile target to x86, not AnyCPU.
The reason your app currently works while being compiled as AnyCPU is because you have "Prefer 32-bit" enabled on the Build tab. This will run your app as 32-bit all the time, even on 64-bit Windows. If this is turned off, AnyCPU will run your app as 32-bit on 32-bit Windows and 64-bit on 64-bit Windows. This will screw with your Access drivers requirements. You cannot mix 32- and 64-bit code in the same process, so if your app is running as 64-bit, you cannot use 32-bit drivers, and the same goes for the other way around.
You must match the architecture of the Access drivers you need to your app, not to Windows. Unless you have a compelling reason to run your app as 64-bit, go back and change the compile target to x86. This will make your app 32-bit only no matter what it runs on and the 32-bit Access drivers will work all the time.
Why should you do this? Because the most popular Office installation, by far, is 32-bit, which already comes with the Access drivers installed. There's no need to install the separate drivers package. Unless, of course, your client is using the Click-To-Run version of Office, which introduces another headache for your app, necessitating installing the separate drivers pack.
|
|
|
|
|
Its just a small data conversion app.
I'm almost done writing the app I'm coverting the data for, so this is fine.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Seems the easier approach would be to import Access tables directly into Sql Server using an "import" task in management studio. It creates the necessary tables.
Your "data conversion app" can then target the imported SQL Server tables without mucking with Access (offline).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|