|
It sounds to me like you may not be marshalling the calls to your controls back on to the UI thread. Whenever you make a call to a control, or set a property, you need to use the "InvokeRequired ...Invoke " pattern. Take a look here[^] - it explains it all. The pattern I speak of is about 1/3 of the way down the page.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
That's not really relevant in an ASP.NET application.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am trying to print a questionnaire which has 6 check-boxes. I am following a tutorial but this tutorial does not have check-boxes. Below prints except for the check-box. The text in the checkbox prints but prints if checked or not. I need some kind of statement to print if checked but cant find any examples of doing so.
private void metroButton3_Click(object sender, EventArgs e)
{
DSprintPreviewDialog.Document = DSprintDocument;
DSprintPreviewDialog.ShowDialog();
}
private void DSprintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bmp = Properties.Resources.dslogo;
Image newImage = bmp;
e.Graphics.DrawString("Customer Name: " + metroTextBox2.Text, new Font("Arial", 16, FontStyle.Regular), Brushes.Black, new Point(25, 180));
e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 12), Brushes.Black, new Point(25, 100));
e.Graphics.DrawString("Computer Make: " + metroMakeBox28.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 250));
e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
I've changed the following but it prints with a True or False
e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Checked + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
|
|
|
|
|
If you are asking what I think you are asking, this[^] is how you write an if statement in C#.
|
|
|
|
|
The framework has a nice tool to help here[^]. Check out the DrawCheckBox Method[^] overloads.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
checkbox control checked property will only return either true or false. Also the text property only returned the text associated with the control.
One way around that I come up is that:
You will have to write an if statement before the e.Graphics.Drawstring.
if(metroCheckBox.checked)
{
>e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
}
else
{
}
Umair
(Software Engineer)
(Interested in C#, .Net, Interfacing, Device Drivers, GIS, WCF, Asp.net, Ajax, Architecture and Design Patterns)
|
|
|
|
|
How an organization should leverage polymorphism in the definition of standards to reduce the lines of code.
|
|
|
|
|
1) By dumping the buzzwords in favour of English that means something without actually inducing vomiting.
2) By doing their own homework rather than trying to get others to do it for them ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You forgot
0) by putting the water in the coffee machine. The Lounge[^]
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I hadn't noticed it was ORT until I saw that one.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Line count is absolutely meaningless.
Source code isn't for computers, silly. Now go tell your instructor that truth and see what happens
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Dear team,
Can you please help me out to integrate the Facebook Marketing API in my windows application using c#.
Please provide me the sample app code if possible, or please provide the URL to hit and the parameter need to pass on that URL.
|
|
|
|
|
|
Please help if any one has worked on itextsharp.
|
|
|
|
|
i have used
using iTextSharp.text;
using iTextSharp.text.pdf;
-------------//usage///
var baseUrl = SecurityContext.BaseUrl;
string urlString = string.Format("{1}Downloads/SalesOrderInvoice.aspx?id={0}", OrderId, baseUrl);
Uri url = new Uri(urlString);
IDownloader htmlToPDFDownloader = new HtmlToPDFDownloader(url);
string fileName = string.Format("Invoice for Order Referecne. {0}", OrderCode);
htmlToPDFDownloader.Download(fileName);
---------------------------------
Create a interface IDownloader.cs
-------------------------
public interface IDownloader
{
object GetDownloadable();
void Download(string fileName);
}
-------------------------
HTMLToPDFDownloader.cs
---------------------------
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.draw;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
namespace sampleproj.Client
{
public class HtmlToPDFDownloader : IDownloader
{
private string htmlString;
public HtmlToPDFDownloader(string htmlString)
{
this.htmlString = htmlString;
}
private string ImageToBase64(string url)
{
WebClient client = new WebClient();
byte[] bytes ;
if(url.StartsWith("http"))
{
bytes = client.DownloadData(url);
}
else
{
string physicalPath = HttpContext.Current.Server.MapPath(string.Format("~{0}", url));
bytes = File.ReadAllBytes(physicalPath);
}
string base64String = Convert.ToBase64String(bytes);
return "data:image/png;base64," + base64String;
}
public HtmlToPDFDownloader(Uri url)
{
WebClient client = new WebClient();
client.Headers.Add("_uidqqweb4324", ConfigurationManager.UserId);
this.htmlString = client.DownloadString(url);
foreach (Match m in Regex.Matches(htmlString, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase | RegexOptions.Multiline))
{
string src = m.Groups[1].Value;
string physicalPath = ImageToBase64(src);
htmlString = htmlString.Replace(src, physicalPath);
}
}
private byte[] GetStream()
{
MemoryStream stream = new MemoryStream();
var htmlContent = this.htmlString;
var converter = new NReco.PdfGenerator.HtmlToPdfConverter();
converter.Margins = new NReco.PdfGenerator.PageMargins
{
Bottom = 5,
Left = 2.5f,
Right = 2.5f,
Top = 5
};
var pdfBytes = converter.GeneratePdf(htmlContent);
return pdfBytes;
}
public object GetDownloadable()
{
return GetStream();
}
public void Download(string fileName)
{
var pdfBytes = GetStream();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf; file";
HttpContext.Current.Response.AddHeader("content-length", pdfBytes.Length.ToString());
fileName = fileName + "_" + DateTime.Now.ToString("ddMMMyyy") + ".pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;" + "filename=" + fileName);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.BinaryWrite(pdfBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
HttpContext.Current.Response.End();
}
}
}
-----------------------------
SecurityContext.cs
-----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EnergyEngineers.Client
{
public class SecurityContext
{
public int CurrentUserId
{
get
{
return 1;
}
}
public static string BaseUrl
{
get
{
return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpRuntime.AppDomainAppVirtualPath;
}
}
}
}
|
|
|
|
|
I've been playing with jsPDF[^] lately. Aside from highly limited CSS support, it's fairly excellent.
The AutoTable plugin also works exceptionally well.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
hi check this link
[^]
|
|
|
|
|
Is there a better way to run the Stop Watch:
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;
using System.Diagnostics;
namespace StopWatch
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Stopwatch StopWatch = new Stopwatch();
private void lblClock_Click(object sender, EventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
{
MessageBox.Show("Sorry you have already started the Timer");
}
else
timer1.Start();
this.StopWatch.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
{
timer1.Stop();
StopWatch.Stop();
}
else
MessageBox.Show("Timer Already Stopped");
}
private void btnPause_Click(object sender, EventArgs e)
{
StopWatch.Reset();
lblClock.Text = "00 HR :00 MIN :00 SEC ";
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan elapsed = this.StopWatch.Elapsed;
lblClock.Text = string.Format("{0:00} HR :{1:00} MIN: {2:00} SEC", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds);
}
}
}
Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace StopWatch.BL
{
public class Time
{
Stopwatch stopwatch = new Stopwatch();
public TimeSpan Elapsed
{
get { return stopwatch.Elapsed; }
}
public bool IsRunning
{
get { return stopwatch.IsRunning; }
}
public void Start()
{
DateTime start = DateTime.Now;
TimeSpan duration = DateTime.Now - start;
}
public void Stop()
{
stopwatch.Stop();
}
public void Reset()
{
stopwatch.Reset();
}
}
}
|
|
|
|
|
This very much depends on the application and level of accuracy required. Your sample provides the simplest solution, but it lacks a degree of accuracy, as everything is processed on the UI thread. Using this system, a timer event is actually placed on the message queue when it is signalled, and thus needs to wait its turn to be processed. This can cause a delay small in the processing of the tick, which over time, may accumulate.
To go to the next level of accuracy, you need to look at a System.Threading.Timer[^]. These fire events off in another thread, so there is no queue delays. It does, however, take a bit of effort to marshal the results back to the UI thread to update your controls.
The most accurate timer is the High Resolution Timer used in the Stopwatch Class[^]. This does not fire its own events at all, so you need to monitor its values in a separate thread, fire the periodic events in another thread, and then marshal all the results back to the UI for display.
All three options are good fun!
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
Don't use a StopWatch - just get the current DateTime.Now when you start the timer, and again when you stop (or lap check) it.
The Timespan difference will give you all the information you need.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ehm, that looks like a hidden bug:
if (timer1.Enabled)
{
MessageBox.Show("Sorry you have already started the Timer");
}
else
timer1.Start();
this.StopWatch.Start();
Did you really mean that? Or rather
if (timer1.Enabled)
{
MessageBox.Show("Sorry you have already started the Timer");
}
else
{
timer1.Start();
this.StopWatch.Start();
}
Anyway, I recommend to always use {} with if and else - also with one-liners.
|
|
|
|
|
There is no problem with your code if that can solve your problem. From design point of view it looks great.
As one answer above mentioned that you can use many other types of solution to accomplish timing and scheduling task. That also depend upon your needs.
If you need a precise timer such as with 1ms accuracy (Stopwatch can very up-to 20-100 ms) then you should use multimedia timers.
Umair
www.objectorienteddesign.org
(Interested in C#, .Net, Interfacing, Device Drivers, GIS, WCF, Asp.net, Ajax, Architecture and Design Patterns)
|
|
|
|
|
Below is my Kendo code:
@(Html.Kendo().ComboBox()
.Name("cboTeamCode")
.HtmlAttributes(new { style = "width:90%;" })
.DataTextField("Team")
.DataValueField("Team")
.Placeholder("Select Team").Filter("contains").AutoBind(false).MinLength(1)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetTeamList", "Main"); //Set the Action and Controller names.
})
.ServerFiltering(true); //If true, the DataSource will not filter the data on the client.
})
.SelectedIndex(0)
)
Below is my Action method:
public JsonResult GetTeamList()
{
return Json(dba.GlobalDefaults, JsonRequestBehavior.AllowGet);
}
When I am running my code I am getting below error:
Error: Object doesn't support property or method 'requestData'
Below is the debugger code:
jQuery(function(){jQuery("#cboTeamCode").kendoComboBox({"dataSource";:{"transport":{"read":{"url":"/Main/GetTeamList","data":function() { return kendo.ui.ComboBox.requestData(jQuery("#cboTeamCode")); }},"prefix":""},"serverFiltering":true,"filter":[],"schema":{"errors":"Errors"}},"dataTextField":"Team","filter":"contains","minLength":1,"autoBind":false,"dataValueField":"Team","index" ,"placeholder":"Select Team"});});
|
|
|
|
|
You might have better luck getting an answer if you ask over in the Web Development forum, where the Web Developers hang out.
|
|
|
|
|
We need a dedicated Cool Development forum; I hear that's where the cool kids hang out.
This space for rent
|
|
|
|
|