|
I understood, in what an error! everything works thanks!
|
|
|
|
|
Easy mistake to make.
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
A Word document is not meant as a data source other than for being read by a human.
If you have to do this for one single document, it's not worth the programming effort: Copy-paste the table into Excel and save it as CSV or XML, then read that file into a DataTable and make the DataTable or its DataView the DataSource of your DataGridView.
If you "plan" on doing this regularly for constantly newly created Word documents, do yourself a BIG favor and get your data from wherever it comes from before it "goes" into the Word document. In case someone types it manually into the Word document, tell him to type it into an Excel sheet first. That Excel sheet can then be used as a source for the table in the Word document and as a source for your DataGridView.
Recursion: see Recursion.
|
|
|
|
|
The file contains a table. It is necessary to take the table out of the file on the form. To me set this task. But how to work with Excel in dataGridView I do not know. Please, tell me.
|
|
|
|
|
You misunderstood me, I didn't mean that you can directly connect Excel with a DataGridView somehow.
But since you already have some code for accessing the table in the Word document, as I've seen from your reply to OriginalGriff, don't mind my answer and follow his advice: Run it in the debugger and analyze what's working and what's not.
Recursion: see Recursion.
|
|
|
|
|
Index outside the range. It in a debugger.
|
|
|
|
|
Try to figure out why by stepping through the code and comparing the values of your variables to your expectation.
Recursion: see Recursion.
|
|
|
|
|
I have a trackbar control that is adjusting the brightness of the background color of a form. Eventually, I'll modify it to adjust an image's brightness. If you look at how the brightness slider works in the colorDialog Control, as you move up and down, the value changes from white to black, but in the middle, the hue of the original color is never lost. The problem with my code is that once I reach the high end of brightness (white), or the low end (black), I lose the hue, and the trackbar becomes an adjustment of grayscale brightness, instead of an adjustment of the original color's brightness. So, I need to know how to change my code to adjust the brightness while preserving the hue.
int valueOne = 0, valueTwo = 0, valueNew = 0;
bool count = true;
private void Form1_BackColorChanged(object sender, EventArgs e)
{
if (count == true)
trackBar1.Value = (this.BackColor.R + this.BackColor.G + this.BackColor.B) / 3;
count = false;
valueOne = trackBar1.Value;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
int bgRed = 0, bgGreen = 0, bgBlue = 0;
valueTwo = trackBar1.Value;
valueNew = valueTwo - valueOne;
bgRed = this.BackColor.R + valueNew;
bgGreen = this.BackColor.G + valueNew;
bgBlue = this.BackColor.B + valueNew;
if (bgRed > 255)
bgRed = 255;
if (bgGreen > 255)
bgGreen = 255;
if (bgBlue > 255)
bgBlue = 255;
if (bgRed < 0)
bgRed = 0;
if (bgGreen < 0)
bgGreen = 0;
if (bgBlue < 0)
bgBlue = 0;
this.BackColor = Color.FromArgb(255, bgRed, bgGreen, bgBlue);
}
Thank you
|
|
|
|
|
Don't use the current BackColor as input for the calculation of the new BackColor. Store the initial BackColor in some additional variable that will never be changed and use that one as input for the calculation of the new BackColor. To adjust for that, don't use the the slider delta but the absolute slider value to calculate the new BackColor.
Currently you do:
BackColor -> apply slider delta -> new BackColor v
^--------------------------------------------|
Suggested:
InitialBackColor -> apply slider position -> current BackColor
Recursion: see Recursion.
|
|
|
|
|
I appreciate the reply. I'm sorry, but I'm really not understanding what you're getting at. Could you provide more details, or perhaps some sample code?
EDIT: To expand on that, one thing I don't understand is what I do with that initial value. Let's suppose I put it in three int variables, int R, G, and B. If I add that to the absolute value of the trackbar, in many cases, the result will be over 255, since I'm using the absolute value of the trackbar instead of the delta. The code will be adjusting this to 255. But this will be resulting in a lot of white results. Which makes me wonder if I'm understanding correctly.
Thank you
modified 21-Mar-15 18:51pm.
|
|
|
|
|
Alright
Let's assume an initial background color of RGB 20/50/150.
1) Determine the color component with the smallest value and subtract it from 255. In this case: (Red) 255-20 = 235
2) Determine the color component with the highest value. In this case: (Blue) 150
3) Set the Maximum of the TrackBar to the sum of those values: 235+150 = 385
4) Set the Value (Position) of the TrackBar to the value from Step 2: 150
5) When the slider gets moved, take its Value and subtract the value from Step 2. Add the result of this to the color components of the initial background color (with Min/Max of 0/255 of course) and set it as current background color.
Example 1:
Let's assume the TrackBar got moved to 0. Then we calculate: 0-150 = -150
R: 20 + -150 = -130 ==> 0
G: 50 + -150 = -100 ==> 0
B: 150+ -150 = 0
Example 2:
Let's assume the TrackBar got moved to 200. Then we calculate: 200-150 = 50
R: 20 + 50 = 70
G: 50 + 50 = 100
B: 150+ 50 = 200
Example 3:
Let's assume the TrackBar got moved to 385. Then we calculate: 385-150 = 235
R: 20 + 235 = 255
G: 50 + 235 = 285 ==> 255
B: 150+ 235 = 385 ==> 255
Looks good?
Edit: If you want to achieve that all three color components reach the min/max value "at the same time" so that no value has to be "clipped" (which will probably produce a better result for image brightness adjustment) you would have to apply some slightly more sophisticated math but I think you'll get the basic idea from the above method.
Recursion: see Recursion.
modified 21-Mar-15 20:17pm.
|
|
|
|
|
Okay, thank you very much for the additional info. I have work to deal with tonight, but I'm looking forward to trying this, I'll let you know how it works out. Thanks again!
|
|
|
|
|
You're welcome!
Recursion: see Recursion.
|
|
|
|
|
Unfortunately, this didn't work. It's still losing its hue once I get down to black or up to white. Suggestions?
Thanks
|
|
|
|
|
Hi there,
I've made the Tic Tac Toe game.
Now I also added the "Multiplayer" function (LAN - TCP - UDP).
My problem is after I created the Multiplayer menutoolstrip and the dialog for the connection, I have some problems to link it up to the game.
Here is my code:
[code]
namespace TicTacToe
{
public partial class Multiplayer : Form
{
Socket sck;
EndPoint epLocal, epRemote;
public Multiplayer()
{
InitializeComponent();
sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
textLocalIp.Text = GetLocalIP();
textFriendsIp.Text = GetLocalIP();
}
private void buttonStart_Click(object sender, EventArgs e)
{
try
{
epLocal = new IPEndPoint(IPAddress.Parse(textLocalIp.Text), Convert.ToInt32(textLocalPort.Text));
sck.Bind(epLocal);
epRemote = new IPEndPoint(IPAddress.Parse(textFriendsIp.Text), Convert.ToInt32(textFriendsPort.Text));
sck.Connect(epRemote);
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
buttonStart.Text = "Connected";
buttonStart.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private string GetLocalIP()
{
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
return "127.0.0.1";
}
private void MessageCallBack(IAsyncResult aResult)
{
try
{
int size = sck.EndReceiveFrom(aResult, ref epRemote);
if (size > 0)
{
byte[] receivedData = new byte[1464];
receivedData = (byte[])aResult.AsyncState;
}
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
}
}
[/code]
Stuck at combining the Multiplayer.cs to the Mainform.cs (The main game)..
Any tip or ideas for letting me continue my work will be appreciated.
Thanks.
|
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http;
using System.Data;
using System.Data.SqlClient;
namespace Fabco_WebApi.Controllers
{
public class DownloadPDFController : ApiController
{
public static string ConnectionString = Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
FabcoDBDataContext _ObjDb = new FabcoDBDataContext(ConnectionString);
[HttpGet]
public HttpResponseMessage Get()
{
string[] FN = Directory.GetFiles(@"C:\XXX");
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
string query = "select * from XXX where convert(datetime,convert(varchar(10),last_update,101))=convert(datetime,convert(varchar(10),'2015-03-19',101))";
SqlCommand Command = new SqlCommand(query, connection);
SqlDataAdapter da = new SqlDataAdapter(Command);
DataSet ds = new DataSet();
da.Fill(ds);
while (true)
{
if (ds.Tables[0].Rows.Count > 0)
{
MemoryStream responseStream = new MemoryStream();
bool fullContent = true;
var fName = string.Empty;
for (int i = 0; i <=ds.Tables[0].Rows.Count; i++)
{
fName = ds.Tables[0].Rows[i][1].ToString();
var DataFlag = ds.Tables[0].Rows[i][7].ToString();
string aa = "C:\\Fabco";
//string fName = "jQueryNotes.pdf";
var filepath = aa + "/" + fName;
//MemoryStream responseStream = new MemoryStream();
Stream fileStream = File.Open(filepath, FileMode.Open);
//bool fullContent = true;
fileStream.CopyTo(responseStream);
fileStream.Flush();
fileStream.Close();
}
responseStream.Position = 0;
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = fullContent ? HttpStatusCode.OK : HttpStatusCode.PartialContent;
response.Content = new StreamContent(responseStream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fName.ToString() };
return response;
}
}
}
}
}
|
|
|
|
|
A single response can only return a single file. If you want to return multiple files, you will need to combine them in a zip file. DotNetZip[^] would probably be a good place to start.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If you want two separate downloads you'll need to make two requests. One technique for doing this is to show the user a page that has two hidden iframes and the src of the iframe is the url of your page that pushes the file to the user.
|
|
|
|
|
Some of programming SDK have some methods what are in draft status or with some bugs. For example 50% of requests hangs up.
How to create some kind of "time exeption" if internet request hangs up or sometimes hangs up.And redo it until success.
About about = service.About.Get().Execute();
ps Analog Delphi IdAntiFreeze. try{} doesn't help.
modified 20-Mar-15 5:45am.
|
|
|
|
|
You could either set a timer to see if server responds in a particular time, or use a try { } catch { } block to manage anything that happens unexpectedly.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
Hello there. I am trying to implement tree node mouse double click event along with context menu strip. Problem is: I have to click three times, in order to get the functionality of node double click. Skeleton of the program is as follows
private void tree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
}
private void tree_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
}
}
What should be done here.... so that I don't have to click three times for the NodeMouseDoubleClick event. Thanks for any input.
modified 20-Mar-15 6:19am.
|
|
|
|
|
Double-clicking on a node means "expand" or "collapse". It then calls those events[^].
You'd have to work against the system to prevent that default-working, as explained on SO here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I am developing an outlook ad-in application.
I am able to build the solution but not able to generate .VSTO and .manifest file.
So i am not able to register the addin.
I am using following development environemnt
VS2010 sp1
outlook 32 bit
windows 2008 server 64 bit OS
Can you please let me know where I need to change or some settings need to be changed?
Thanks,
SMA
|
|
|
|