|
Depending on whether you want to do it before or after compilation it's easy to do in VS: Look under the project properties and you will see a "Build events" tab on the right hand side.
You can enter any CMD or Powershell commands in there and they will be executed (I use them to timestamp assemblies: Timestamping assemblies with Build date and time.[^] but you can do pretty much anything in there)
You can't cause a file to be deleted each time you execute your app though - not unless your app actually does the delete itself (which is easy enough to do) - because VS isn't necessarily involved in each execution: you can double click any exe file, even debug ones and they will run on their own.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have a Windows Forms Application and added a User Control to the project. The User Control contains a TextBox and a button, the button opens FolderBrowseDialog, however the drag and drop code section is not working. If I use the drag and drop code on a Form without a User Control it works perfectly, but not contained within the User Control on a Form. Not sure on how to go about this, any advice will be greatly appreciated.
Form1.cs:
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;
namespace TestCopyFolder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
ucCopyDir.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestCopyFolder
{
public partial class ucCopyDir : UserControl
{
public ucCopyDir()
{
InitializeComponent();
}
private void txtBoxCpSrc_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
e.Effect = DragDropEffects.All;
}
}
private void txtBoxCpSrc_DragDrop(object sender, DragEventArgs e)
{
string[] files1 = (string[])e.Data.GetData(DataFormats.FileDrop,false);
foreach (string file1 in files1)
txtBoxCpSrc.Text = file1;
}
private void btnCpSrcBrowse_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
txtBoxCpSrc.Text = (fbd.SelectedPath);
}
}
}
}
modified 22-Nov-19 5:05am.
|
|
|
|
|
Did you set the AllowDrop property on the TextBox to true? Without it, drag and drop won't work.
|
|
|
|
|
Hi Dave
Thank you for the reply, the AllowDrop property is set to true, I tried setting the User Control AllowDrop to false and only the textBox to true as well, without any success.
Just an update:
I had to specify the methods in the Events 'DragDrop' and 'DragEnter' of the textBox Events respectively, for it to work.
DragDrop: txtBoxCpSrc_DragDrop
DragEnter: txtBoxCpSrc_DragEnter
Thanks again
modified 22-Nov-19 4:39am.
|
|
|
|
|
That was my next question. Did the events get wired up? You look in the .designer.cs file to make sure the events show up and are wired to the methods you expect them to be wired up to.
|
|
|
|
|
The events were blank so I wired them up to the correct methods, tested, and it worked.
Thank you for your time and help, I appreciate it.
|
|
|
|
|
I want to evaluate an a string math expression , so before i want to extract variables so i have to remove all special characters my code only can remove a special character like `a+b*c` and the result i get is `a=;b=;c=`, now if i write two successive special characters like `(a+b)*c` and `a++b` results will be `=;a=;b=;c=` and `a=;=;b=` always there is a sign `=;` added for no reasons how get rid of them because after that i will use mathematic functions so that will be a real problem for me please help me ! here is my code
public string RemoveSpecialCharacters(string str)
{
StringBuilder sb = new StringBuilder();
for(int i=0; i<str.Length;i++)
{
if((str[i] >= '0' && str[i] <='9')
||( str[i] >='A' && str[i]<='z'|| (str[i]=='-' || str[i] == '+' || str[i] == '*' || str[i] == '/' || str[i] == '%'|| str[i] ==')' || str[i] == '(')))
{
sb.Append(str[i]);
}
}
return sb.ToString();
}
private void button8_Click(object sender, EventArgs e)
{
string refine_string = RemoveSpecialCharacters(textBox1.Text);
string[] split_var = refine_string.Split('+', '-', '/', '%', '^', '*', '=',')','(');
double value;
string str = "";
for (int i = 0; i < split_var.Length; i++)
{
if (double.TryParse(split_var[i], out value))
{
split_var[i] = " ";
}
}
split_var = split_var.Where(s => s != " ").ToArray();
string[] variables = split_var.Distinct().ToArray();
for (int j = 0; j < variables.Length; j++)
{
str = str + variables[j] + '=' + ";";
}
textBox2.Text = str.TrimEnd(';');
}
|
|
|
|
|
|
How can i use that ! help me
|
|
|
|
|
It's an article: read it and it will explain.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm trying to build a dynamic menu from database and pass it to DevExpress Menu control my table looks like:
(Primary)
(int) - nvarchar(50) - (int)
Iserial - Department - ParentIserial
if the department has no parent then ParentIserial = 0 otherwise it will = the parent's Iserial
Ibuilt the model like this
public class TblDepartments {
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Iserial { get; set; }
public nvarchar(50) Department { get; set; }
public int ParentIserial{ get; set; }
public IEnumerable<TblDepartments> items { get; set; }
}
and I was following this link
Overview - ASP.NET Core Menu Demo | DevExpress[^]
so please tell me how to build the structure same as the have done it on their demo to pass it to the control
Thanks in advance
JusT LeT YouR MinD WorK
|
|
|
|
|
Why not ask the people who wrote the demo? You have a licence to use the controls, which gives you access to tech support from them - so use it!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I don't only need the code I need to understand it
|
|
|
|
|
Again, why not ask them? They know their demo better than we will ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I already asked them but still no reply,
However what I need is to understand how to populate sql server table to build the dynamic menu no matter to devexpress or even writing the html manually
I hope you got my point
|
|
|
|
|
Your class defines the table structure required (and vice versa) so
ID - IdentityField
ISerial - int - probably defines the sort order within the parents collection
Department - self evident
ParentISerial - I think thes is wrong as it should be the ParentID field
Add the collection of children in the client.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Thanks for your reply
can you please give more clarifications ?
|
|
|
|
|
I have a utility library which mutitarget netcoreapp3.0, net472 and netstandard2.0.
I use netstandard2.0 on the phone application
Internally I have some #if statement to use DynamicMethod (i.e. code generation) on net472 and netcoreapp3.0 and reflection on netstandard2.0
Ultimately though, what I'd like to to is use netstandard2.1 and decide at runtime (as opposed to at compile time) whether to use reflection or emit based on current platform capability.
Which bring me to my question: how to I detect whether DynamicMethod / Emit is being supported by platform?
modified 19-Nov-19 19:31pm.
|
|
|
|
|
I simply added an autodetection method in the static constructor
static EmitHelper()
{
try
{
var dynam = new DynamicMethod(string.Empty, typeof(int), new Type[] { typeof(int) }, Module, true);
ILGenerator il = dynam.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Mul);
il.Emit(OpCodes.Ret);
var sq = (Func<int, int>)dynam.CreateDelegate(typeof(Func<int, int>));
if (sq(2) == 4)
{
SupportsEmit = true;
}
}
catch { }
}
public static bool SupportsEmit { get; private set; }
Will test it tomorrow an Android!
Got my hands full enough tonight with netcoreapp3.0 port!
|
|
|
|
|
A simple, fast, thread safe Object Pool library.
GitHub[^]
|
|
|
|
|
Rather than posting information free messages that just look like spam, why not post this either as a Project: Your GitHub Project on CodeProject[^] - you will need a readme.md file in the GitHub project, and the better that is the better the chnaces of moderators approving it;
or as an Article: Submit a new Article[^] - you will need to explain how it works in order to pass moderation.
Just posting a link here? Unlikely to get you many users!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for the suggestion, I with using an article format.
|
|
|
|
|
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I have the code below for scanning all papers. It works but the problem is when all papers will finish, it shows the error:
Exception User-Unhandeled System.runtime.InterpService.COMEException: Exception From HRESULT:0*80210003
which belongs to this line:
var imgFile = (ImageFile)ScanerItem.Transfer();
Does anyone know how to fix it?
Thanks
How can i fix it? Here is the code:
bool continueScanning2 = true;
try
{
await Task.Run(() =>
{
var deviceManager = new DeviceManager();
DeviceInfo AvailableScanner = null;
while (continueScanning2)
{
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
{
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
{
continue;
}
AvailableScanner = deviceManager.DeviceInfos[i];
break;
}
var device = AvailableScanner.Connect();
var ScanerItem = device.Items[1];
var imgFile = (ImageFile)ScanerItem.Transfer();
var data = (byte[])imgFile.FileData.get_BinaryData();
var bitmap = GetBitmapFromRawData(imgFile.Width, imgFile.Height, data);
string name2 = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
var Path = @"C:\Users\...\Desktop\test\" + name2;
pictureBox1.ImageLocation = Path;
bitmap.Save(Path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
});
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
|
|
|
|