|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have an Ink Canvas control on my application. Is it possible that whenever i draw a line, there's a value that appears between on that line by the use of C#?
Here is my code, XAML:
<DockPanel>
<StackPanel DockPanel.Dock="Bottom">
<Button x:Name="ClearButton" Content="Clear" Click="ClearButton_Click"/>
<Button x:Name="SaveButton" Content="Save" Click="SaveButton_Click"/>
</StackPanel>
<InkCanvas x:Name="DrawingPane" Cursor="Cross" Background="White"/>
</DockPanel>
And here is my C# code:
namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
private void ClearButton_Click(object sender, RoutedEventArgs e)
{
DrawingPane.Strokes.Clear();
}
}
}
I hope you can help me out for this. Thank you.
|
|
|
|
|
Since this is not "just" C#, you should post this in the right forum: Silverlight / WPF Discussion Boards[^] for the best results.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This is from the top of my head so you'll have to work out the details yourself.
Catch the events mousedown and mousemove. If the mouse moves AND mouse button is down you're drawing (or so I assume).
You'll need to find out the coordinates from your canvas where top-left = 0,0 and x moves up to the right and y moves up going down! It might be you need to fiddle with it to get the right coordinates as windows tends to work with multiple sets (your window, your control, the screen, ...)
Once you have the correct coordinates and you start drawing a line (= first point is known) you can calculate the length of your line: sqrt((x2-x1)^2 + (y2-y1)^2) use your mouse location to get the second point.
To set that value on screen, draw a string on the location (x2+x1)/2 and (y2/y1)/2.
This solution should at least get you a bit further, but again, this is on top of my head, you'll need to figure out a lot of it yourself.
|
|
|
|
|
You don't draw "between" an object (i.e. the line); only "over" (or under).
Determine "where" the "value" should go, and simply place a Label, TextBlock, TextBox, Image, etc. with the appropriate styling (e.g. Margin; transparent background) there.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi programmer friend, I finished my software that is connected to a SQLite database that works perfectly and I wanted to deploy it on another machine. I have an error message: Can not load file or assembly 'System.Data.SQlite.
Version = 1.0.108.0. Culture = neutral. PublicKeyToken = db937bc2d44ff139 '
or one of his dependencies. The specified file can not be found
Thank you for bringing me your help here is the connectoin code:
(
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SQLite;
namespace Acode
{
public partial class Form1: Form
{
public Form1 ()
{
InitializeComponent ();
}
private SQLiteConnection sql_con;
private SQLiteCommand sql_cmd;
private SQLiteDataAdapter DB;
private DataSet DS = new DataSet ();
private DataTable DT = new DataTable ();
private void setConnection ()
{
// CONNECTING TO THE DATABASE
sql_con = new SQLiteConnection (@ "Data Source = DBcode.db; Version = 3; New =; Compress = True;");
}
private void LoadData ()
{
SetConnection ();
sql_con.Open ();
sql_cmd = sql_con.CreateCommand ();
string CommandText = "select * from InfoCode";
DB = new SQLiteDataAdapter (CommandText, sql_con);
DS.Reset ();
DB.Fill (DS);
DT = DS.Tables [0];
dataGridView1.DataSource = DT;
sql_con.Close ();
}
private void Form1_Load (object sender, EventArgs e)
{
LoadData ();
}
private void ExecuteQuery (String txtQuery)
{
SetConnection ();
sql_con.Open ();
sql_cmd = sql_con.CreateCommand ();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery ();
sql_con.Close ();
}
public static string randomstring (int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";
Random random = new Random ();
return new string (Enumerable.Repeat (floats, length) .Select (s => s [random.Next (s.Length)]). ToArray ());
}
private void btnGenerer_Click (object sender, EventArgs e)
{
lblDisplay.Text = randomstring (4);
txtAfficPrice.Text = "100";
}
private void button1_Click (object sender, EventArgs e)
{
lblDisplay.Text = randomstring (5);
txtAffichPrice.Text = "300";
}
private void button2_Click (object sender, EventArgs e)
{
lblDisplay.Text = randomstring (6);
txtAffichPrice.Text = "500";
}
private void btnRegister_Click (object sender, EventArgs e)
{
if (lblDisplay.Text == "")
{
MessageBox.Show ("Please generate the code");
}
else
{
using (SQLiteConnection con = new SQLiteConnection (sql_con))
{
try
{
con.Open ();
// Insert code to process data.
using (SQLiteCommand cmd = new SQLiteCommand ("INSERT INTO InfoCode (Code, DateCode, PriceCode) VALUES (@Code, @DateCode, @CodePrice)", con))
{
cmd.Parameters.AddWithValue ("@ Code", lblDisplay.Text);
cmd.Parameters.AddWithValue ("@ DateCode", dateTimePicker1.Text);
cmd.Parameters.AddWithValue ("@ PriceCode", txtAfficPrice.Text);
cmd.ExecuteNonQuery ();
}
LoadData ();
MessageBox.Show ("Registration completed successfully");
lblDisplay.Text = "";
groupBoxGenerer.Enabled = false;
btnSave.Enabled = false;
btnPrint.Enabled = true;
This.Refresh ();
}
catch (Exception ex)
{
MessageBox.Show ("Failed to connect to data source" + ex.Message);
}
finally
{
con.Close ();
}
}
}
}
private void btnAdd_Click (object sender, EventArgs e)
{
groupBoxGenerer.Enabled = true;
btnSave.Enabled = true;
}
private void exitToolStripMenuItem_Click (object sender, EventArgs e)
{
this.Close ();
FrmAuthentification
|
|
|
|
|
|
OK I install it and I give you the rest
thank you for your promptitude
|
|
|
|
|
Thank you thank you and thank you you just relieved me of a problem that tired me for a long time. I followed your advice and walk. But my question is the following, if I will have to burn it on a CD to give it to a friend or mm has everyone how to go about it so that in the course of installatoin the sytem.data.sqlite installs automatically?
|
|
|
|
|
You need to follow the instructions of your setup builder. I think external libraries need to be added as dependencies.
|
|
|
|
|
I use inno setup. i made a comment when i was installing my program on the pc it asked me the framwork .NET 3.5 which is launching once i have accepted but for the system.data.sqlite no ...
|
|
|
|
|
SQLite is not part of the standard .NET framework, it must be downloaded from the SQLite website.
|
|
|
|
|
Hello sir and thank you for your answer ...
I will like some advice about my program. If I want to give it to friends, I have to ask them to install system.data.sqlite on their pc? But is there not another alternative?
|
|
|
|
|
The alternative is that you add the requirement to your setup program, so it is automatically installed. Check the documentation for the setup generator that you are using.
|
|
|
|
|
Thank you I use inno setup, I will document and make you a continuation of my research
|
|
|
|
|
I just realized that although I managed to connect to my database thanks to you, I can not register ... here is the error message:
Failed to connect to the data source attempt to write a readonly database
attempt to write a readonly database
|
|
|
|
|
You need to check your code and your setup. Either the database is in a protected folder, or your open statement needs an extra parameter.
|
|
|
|
|
I send you my code and if possible give me a link or I can send you all the program for inspection on your part
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SQLite;
namespace Acode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SQLiteConnection sql_con;
private SQLiteCommand sql_cmd;
private SQLiteDataAdapter DB;
private DataSet DS = new DataSet();
private DataTable DT = new DataTable();
private void setConnection()
{
sql_con = new SQLiteConnection(@"Data Source=DBcode.db; Version=3;New=;Compress=True;");
}
private void LoadData()
{
setConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "select * from InfoCode";
DB = new SQLiteDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
LoadData();
}
private void ExecuteQuery(String txtQuery)
{
setConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery();
sql_con.Close();
}
public static string randomstring(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";
Random random = new Random();
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
private void btnGenerer_Click(object sender, EventArgs e)
{
lblAffichage.Text = randomstring(4);
txtAffichPrix.Text = "100";
}
private void button1_Click(object sender, EventArgs e)
{
lblAffichage.Text = randomstring(5);
txtAffichPrix.Text = "300";
}
private void button2_Click(object sender, EventArgs e)
{
lblAffichage.Text = randomstring(6);
txtAffichPrix.Text = "500";
}
private void btnEnregistrer_Click(object sender, EventArgs e)
{
if (lblAffichage.Text == "")
{
MessageBox.Show("Merci de bien vouloir générer le code");
}
else
{
using (SQLiteConnection con = new SQLiteConnection(sql_con))
{
try
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO InfoCode (Code, DateCode, PrixCode) VALUES (@Code, @DateCode, @PrixCode)", con))
{
cmd.Parameters.AddWithValue("@Code", lblAffichage.Text);
cmd.Parameters.AddWithValue("@DateCode", dateTimePicker1.Text);
cmd.Parameters.AddWithValue("@PrixCode", txtAffichPrix.Text);
cmd.ExecuteNonQuery();
}
LoadData();
MessageBox.Show("Enregistrement effectué avec succès");
lblAffichage.Text = "";
groupBoxGenerer.Enabled = false;
btnEnregistrer.Enabled = false;
btnImprimer.Enabled = true;
this.Refresh();
}
catch (Exception ex)
{
MessageBox.Show("Échec de la connexion à la source de données" + ex.Message);
}
finally
{
con.Close();
}
}
}
}
private void btnAjouter_Click(object sender, EventArgs e)
{
groupBoxGenerer.Enabled = true;
btnEnregistrer.Enabled = true;
}
private void quitterToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
FrmAuthentification retour = new FrmAuthentification();
retour.Show();
}
private void codeVenduToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmCodeVendu ventcode = new FrmCodeVendu();
ventcode.Show();
this.Hide();
}
private void pointToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmPointJournalier pointQ = new FrmPointJournalier();
pointQ.Show();
this.Hide();
}
private void btnImprimer_Click(object sender, EventArgs e)
{
FrmImprimer imprmer = new FrmImprimer();
imprmer.Show();
this.Hide();
}
private void imprimerToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmImprimer imprmer = new FrmImprimer();
imprmer.Show();
this.Hide();
}
}
}
|
|
|
|
|
Sorry, I have no idea why you have posted all that code. You need to do some investigation and debugging to find out what is happening.
|
|
|
|
|
ok sir i'm doing some research and giving you a follow up of my research.
Thank you for your patience and your availability
|
|
|
|
|
The files you need to "distribute" are in your "bin\Release" folder.
Create your setup and test on your machine.
Then "zip it" and send it to your fiends via the "cloud".
No "CD burning".
DVD/CD drives are "optional" these days ... not the ".NET framework"; unless your friends are running XP.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you sir but I have an error message when I want to make a recording: Failed to connect to the data source
attempt to write a readonly database
I am looking for documentation to this problem but not in continuation
|
|
|
|
|
What's "in the database"? Nothing? Then create it on site.
Read SQLite goes "read only" with certain installations; nothing to do with C#.
Google "sqlite read only" for lots of "answers".
Shoulda used SQL Server CE.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hello Gerry Schmitz and thank you for your help, I will document and make you a return, But I would like you to guide me on a code that I saw during but research:
Read only connection
Data Source = c: \ mydb.db; Version = 3; Read Only = True;
I even use this connection but the same error message is displayed ...
|
|
|
|