lundi 30 mars 2015

Animate Richtext Box using scrolbar in c# [on hold]

I have a richtext box in which data is added after every 3-4 minutes,


I want that scrol bar should auto scrol up and down so that it creates a animated effect ...


Which event is fired when I navigate to any other application in my PC?

I have a Custom Control of following type in .NET C# Winforms



public partial class AutoSuggestPopupList : ToolStripDropDown
{
}


It has got all its properties and methods. I am using it with a ListBoxControl and a textbox/combobox.


It is used in following manner: 1. As user types something in textbox/combobox 2. the list of ListBoxControl is refreshed and accordingly the items of AutoSuggestPopupList are refreshed.


I am closing my AutoSuggestPopupList in different Event Handlers and it gets closed appropriately. But my only problem is when I navigate to any other software like Word or Excel from my App, the AutoSuggestPopupList is not closed and is fixed at its location.


I have already tried using frm_LocationChanged and frm_VisibleChanged Event Handlers, but of no use :(


It will be a great help if some one can tell me which event handler will be useful for me , when i navigate to any other software.


How can I find File name in string which start with # Using RegEx

I have string :



" testfile.txt #testfile.txt
My new message
Filename1.doc #filename.doc"


How can I find file name starting with '#' and remove it from string


F# Winforms Charting Asynchronous Updating

I'm trying to create a chart in winforms that databinds to a list in memory, and gets updated dynamically as the list changes. Here is my code:



open System
open System.Linq
open System.Collections
open System.Collections.Generic
open System.Drawing
open System.Windows.Forms
open System.Windows.Forms.DataVisualization
open System.Windows.Forms.DataVisualization.Charting

let link = new LinkedList<double>()
let rnd = new System.Random()
for i in 1 .. 10 do link.AddFirst(rnd.NextDouble()) |> ignore
let series = new Series()
let chart = new System.Windows.Forms.DataVisualization.Charting.Chart(Dock = DockStyle.Fill, Palette = ChartColorPalette.Pastel)

series.Points.DataBindY(link)

let form = new Form(Visible = true, Width = 700, Height = 500)
form.Controls.Add(chart)

let formloop = async {
while not chart.IsDisposed do
link.AddFirst((new System.Random()).NextDouble()) |> ignore
link.RemoveLast()
}
do
Async.StartImmediate(formloop)
Application.Run(form)

Console.WriteLine("Done")
Console.ReadLine() |> ignore


The async seems to work, but the chart never shows anything. It just shows a blank window. What am I doing wrong?


Application.DoEvents Never Exits

I'm working on a legacy application which has sprinklings of Application.DoEvents here and there. I'm fully aware that this is frowned upon due to re-entrancy issues, but re-factoring isn't currently an option.


An issue has started to occur where DoEvents never exits. The UI is responsive (I can see UI thread activity in the user logs) so DoEvents seems to be pumping the messages, but for some reason it never completes. Unfortunately this DoEvents is in the main data-processing component, which means this stops processing server responses as it's stuck on the DoEvents line.


We have Stopwatch trace which tells how long the DoEvents ran for - staggeringly I got a log where it said it was running for 188267770 milliseconds, which is 52 hours (gulp). It seemed to get into this state at about 3am on a Saturday, until the user came in on Monday and shut the app down (not killing the process, I can see the GUI thread trace closing things gracefully), at which point the DoEvents completes and the timer data is logged (so something which happens during shutdown must convince DoEvents to complete).


Of course, this only happens on the production user's machines, and not on my dev box :)


Has anyone ever seen a similar problem to this?


I've decompiled DoEvents and also how Conrol.BeginInvoke pushes method delegates onto the GUI thread using the Windows message queue, but I cannot see how DoEvents can get stuck like this, and keep the UI responsive.


Source control diff is also not an option since there's been around 30 versions since the last 'good' version the users had, and this new version with the problem - so about 200 files have changed.


Many thanks Paul


How to assign one chart to another C#

I'm attempting to open a chart in another window form, however the classes used for the data in the chart is in the first form. My goal here is to have a chart be able to open many times in a modeless window.


in form1.cs I build my chart:



Chart chart = new Chart();
Series price = new Series("Price"); //create new series
chart.Series.Add(price);

chart.Series["Price"].ChartType = SeriesChartType.Candlestick;

chart.Series["Price"]["OpenCloseStyle"] = "Candlestick";

chart.Series["Price"]["ShowOpenClose"] = "Both";


chart.Series["Price"]["PriceUpColor"] = "Green"; //Price increase = green
chart.Series["Price"]["PriceDownColor"] = "red"; //price decrease = red

for (int i = 0; i < data.Count; i++)
{
chart.Series["Price"].Points.AddXY(data[i].getDate(), data[i].getHigh()); //Adds date and high value
chart.Series["Price"].Points[i].YValues[1] = System.Convert.ToDouble(data[i].getLow()); //Low value added to chart
chart.Series["Price"].Points[i].YValues[2] = System.Convert.ToDouble(data[i].getOpen()); //open value added to chart
chart.Series["Price"].Points[i].YValues[3] = System.Convert.ToDouble(data[i].getClose()); //close value added to chart
}


Form2.cs:



public void DisplayChart(Chart newChart)
{
chart1 = newChart;
chart1.Show();
}

System.Data.DataRowView shows in winforms combobox instead of actual data

After I load my combobox, it displays System.Data.DataRowView instead of data. I am using the correct column names as returned from the stored procedure (TimeframeDesc and TimeframeCode).


I get the message 'Cannot bind to the new display member' when debugging.



private bool loadTimeframeList(out string msg)
{
msg = "";
string spName = "schemaExec.SelTimeframeCode";
bool result = true;
SqlCommand cmd = new SqlCommand(spName);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = _sqlConn;

try
{
SqlDataAdapter rdr = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
rdr.Fill(dt);

cbTimeframe.DisplayMember = "TimeframeDesc";
cbTimeframe.ValueMember = "TimeframeCode";
cbTimeframe.DataSource = dt;
}
catch (Exception ex)
{
result = false;
msg = "Could not load Timeframe Codes" + Environment.NewLine + ex.Message;
}
return result;
}