|
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.
Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterday's shirt when you took it off last night.
We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!
Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, VS will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, VS will stop before the error, and let you examine what is going on by stepping through the code looking at your values.
But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wayland - Phoronix Forums
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
|
|
|
|
|
Hi
I want to use a local database for user and password records. I'm not sure which one of SQLLight or SQL Comact should be used. I tried to install SQLLight/SQL CE tool into my Visual Studio. But I think table creation is not user friendly. Is there another way to create SQLLight/ Compact file outside the visual studio and then using the db file inside Visual Studio?
|
|
|
|
|
SQLite/SQL Server Compact Toolbox - Visual Studio Marketplace
And to create databases in your app, just pass SQL DDL statements (e.g. CREATE, etc) to the engine.
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
|
|
|
|
|
I use DB Browser to manage SQLIte databases.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hi Everyone,
I am trying to make a program which creates a pdf file contains whatever drawn at panel.
I want user to draw signature into panel and once button is clicked it will be saved as pdf.
Is this possible? Thank you at advance.
|
|
|
|
|
RedPandinus wrote: Is this possible?
Yes.
Next question?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
Image bmp = new Bitmap(panel1.Width, panel1.Height);
var gg = Graphics.FromImage(bmp);
var rect = panel1.RectangleToScreen(panel1.ClientRectangle);
gg.CopyFromScreen(rect.Location, Point.Empty, panel1.Size);
bmp.Save("Test.jpg", ImageFormat.Jpeg);
Graphics g = panel1.CreateGraphics();
g.Clear(Color.White);
}
Above is the click event does not create just panel area. It contains some parts of panel.
How can I get just panel area ? I just added the jpg file which button creates.
https://i.postimg.cc/Y0q0Xsp8/Test.jpg[^]
I am beginner at programming so please let me know if I have to elaborate more.
Maybe picturebox or canvas might be useful here I don't know and am open for advise.
My idea was to create .jpg and show it on pdf with using itextsharp.dll.
Thank you.
modified 20-Dec-20 2:40am.
|
|
|
|
|
First off, you are creating objects which use significantly scarce resources, and so require Disposal or you app will crash with "out of memory" errors pretty quickly.
You are responsible for all Graphics objects you create, and all Images - and the Garbage collector will not get called in to dispose of them if you run out of handles for example.
Reworking your code to do that:
using (Image bmp = new Bitmap(panel1.Width, panel1.Height))
{
using (Graphics gg = Graphics.FromImage(bmp))
{
Rectangle rect = panel1.RectangleToScreen(panel1.ClientRectangle);
gg.CopyFromScreen(rect.Location, Point.Empty, panel1.Size);
bmp.Save(@"D:\Temp\AAATest.jpg", ImageFormat.Jpeg);
using (Graphics g = panel1.CreateGraphics())
{
g.Clear(Color.White);
}
}
}
And trying it gives me the panel itself, the whole panel, and no other image content.
So what am I doing that you aren't?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you , I tried your code there but I still cant see just panel area.
Below is the whole code, anything wrong or missed here?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace panel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
float PointX = 0;
float PointY = 0;
float LastX = 0;
float LastY = 0;
private void Form1_Load(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics G = panel1.CreateGraphics();
G.DrawLine(Pens.Black, PointX, PointY, LastX, LastY);
LastX = PointX;
LastY = PointY;
}
private void button1_Click(object sender, EventArgs e)
{
using (Image bmp = new Bitmap(panel1.Width, panel1.Height))
{
using (Graphics gg = Graphics.FromImage(bmp))
{
Rectangle rect = panel1.RectangleToScreen(panel1.ClientRectangle);
gg.CopyFromScreen(rect.Location, Point.Empty, panel1.Size);
bmp.Save(@"AAATest.jpg", ImageFormat.Jpeg);
using (Graphics g = panel1.CreateGraphics())
{
g.Clear(Color.White);
}
}
}
}
private void panel1_MouseDown_1(object sender, MouseEventArgs e)
{
LastX = e.X;
LastY = e.Y;
}
private void panel1_MouseMove_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
PointX = e.X;
PointY = e.Y;
panel1_Paint(this, null);
}
}
}
}
StartPosition is centerscreen if it matters and autoscalemode is DPI.
modified 21-Dec-20 15:09pm.
|
|
|
|
|
Is it possible to detect motion from a picture box? I was looking at AForge for the motion detection class, but because the picture box is not exactly a video source, and currently what I have draws an image when a timer ticks every say 100ms to the box. Could it be possible to detect motion from the picture box?
Or convert the realtime images drawn in a picture box to a video source for Realtime processing of motion?
|
|
|
|
|
"Motion" is when the previous frame (picture) is not the same as the current frame.
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
|
|
|
|
|
Correct, so in theory it could work since the picturebox is being replaced with a new layer/frame ever second that timer draws a new bitmap image?
I have a picture box that draws the recording of my desktop
private void tmrImageUpdate_Tick(object sender, EventArgs e)
{
var img = new Bitmap(this.Height, this.Width);
var grph = Graphics.FromImage(img);
grph.CopyFromScreen((Cursor.Position.X-(pbImageRelay.Height/2)),(Cursor.Position.Y-(pbImageRelay.Width / 2)), 0, 0, img.Size);
pbImageRelay.Image = img;
}
private void Form1_Load(object sender, EventArgs e)
{
Rectangle resolution = Screen.PrimaryScreen.Bounds;
tmrImageUpdate.Tick += tmrImageUpdate_Tick;
tmrImageUpdate.Enabled = true;
tmrImageUpdate.Start();
}
I am trying to detect the motion in say a video player from the desktop, but within the picture box that is viewing on my desktop. Like a picture in a picture on a TV screen, except on PC.
|
|
|
|
|
Basically, you want "screen copy" the image you just loaded and check that for motion. Something you could accomplish by just focusing on the original images. Okaaay.
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
|
|
|
|
|
"Okaaay" like you understand my request? Or "Okaaay" like you're being a pompous-dick right now? I mean, I'll understand if you don't know the answer to the question, it's OK to not know everything. But, if you don't know, save me the ridicule and move on, your forum-troll level of insecurity is not required in this thread.
Not everyone who comes in here is on your level, in fact majority of the people that come in here are have some level of knowledge in IT that doesn't equate to your standard of knowledge. That is why I am here, either help or don't help.
Had you in fact read the thread, you would know that nothing of a 'still image' was mentioned, after all Videos are just layered images. Since my picturebox is technically showing a video of my desktop, rather than using Video File Writer is it possible to put these layers into a MemoryStream read it from there?
modified 20-Dec-20 19:06pm.
|
|
|
|
|
The "picture box" shows an "image"; i.e. a "still".
The "media element" can show "videos"; a series of frames (i.e. more than one "still").
Your picture box is not "technically" showing a video, since by definition, one image does not a video make.
Taking screen captures, still amounts to a bunch of "stills". With varying "frame rates".
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
|
|
|
|
|
I've found a potential solution in replicating what I am looking for by using Accord VideoFileWrite to write the sequence of frames that bitmap creates, using the PictureBox as a "previewer" to show the height/width of what is being recorded. Is it possible to write VideoFileWrite into a memorystream and use AForges motion detection to read the memorystream or a buffer within the specific moment , rather than the read a file thats been written to the computer.
Example Illustration
|
|
|
|
|
You would need multiple threads:
1) one to capture and "buffer"
2) another to handle the "stills" (picture box ui thread) from a concurrent queue
3) another to handle the recording (async file writes)
A "movie" is about 30 frames per seconds (fps); virtual reality needs to run at least at 90 fps or it causes "motion sickness"; "best" is 120 fps.
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
|
|
|
|
|
Hi,
I use SQL Server 2019. I have created a simple database in SQL Server and made a connection in C# (Visual Studio 2019) with that SQL database. I can read and write information on that SQL database using C#. My problem is that my final application wouldn't have access to the SQL Server because it is in my PC and connects using my windows user/pass. How can I make my database dynamic so my users can access it?
|
|
|
|
|
You connect to a sql db using a connection string. Somewhere in your code or web.config or app.config (depending on what type of project you have) is a connection string which tells the code how to connect to the sql database.
You can either put the database somewhere everyone has access to and update your connection string to point to it or you can expose your database on the network, which it might already be.
|
|
|
|
|
Google "sql server allow remote connections"
|
|
|
|
|
I' ve a ComboBox with Three Items in main Form and a button make another form.show so in the second form i am asking about the selected item in the combox and switch it in 3 cases but i ve an error said nullReference the item is null even i select one item from the Combox ( "Tete", "Doublette", "Triplette")
Thank you for Your Help
|
|
|
|
|
Without seeing the relevant code, it's impossible to tell you anything useful beyond something is null and you're trying to use a property or call a method on it.
|
|
|
|
|
|
A "selected item" is not "valid" unless the .SelectedIndex is > -1 (i.e. >= 0);
A "list control" can have items, but the SelectedIndex says whether or not it is actually "pointing" at something.
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
|
|
|
|