|
I'm pretty sure no one is going to open that link.
|
|
|
|
|
And nobody is going to fix your code for you.
Why should we (doing this for free) do your job for you (YOU get paid for it)?? Do you see a problem with this??
|
|
|
|
|
hi every body
i wish i could find somebody help
i want my window to be shown slowly from left corner up and then go down when a button clicked and after a atimer interval the form shown again
this the code i tries but the form doesnt shown again
<pre>namespace moving_form
{
public partial class Form1 : Form
{
bool flag = true;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Left = 0;
this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{ flag = true;
if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
this.Top = this.Top - 10;
}
private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
flag = false;
if (this.Top > Screen.PrimaryScreen.Bounds.Height)
{
return;
}
else
{
this.Top = this.Top + 10;
flag = true;
}
}
}
}
thanx again
|
|
|
|
|
Maybe you didn't start your timer?
|
|
|
|
|
no,
unfotunately its enabled and sterted
|
|
|
|
|
Edit :
I changed your code but yeah it's messy.
My advice,
* Reduce timer usage
* Stop your timer when you don't need them (not keep returning)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer3.Interval = 1000;
}
bool flag = true;
int delay = 0;
private void Form1_Load(object sender, EventArgs e)
{
this.Left = 0;
this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
flag = true;
if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
{
this.Top = this.Top - 10;
}
else
{
timer1.Enabled = false;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
flag = false;
if (this.Top > Screen.PrimaryScreen.Bounds.Height)
{
timer2.Enabled = false;
timer3.Enabled = true;
return;
}
else
{
this.Top = this.Top + 10;
flag = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = true;
}
private void timer3_Tick(object sender, EventArgs e)
{
if (this.delay >= 5)
{
this.delay = 0;
timer1.Enabled = true;
timer3.Enabled = false;
}
else
{
this.delay += 1;
}
}
}
modified 16-Sep-13 0:37am.
|
|
|
|
|
thaks alot the code ig going down an back up when button pressed
but there is one more thing
how can i make the form come up again after two minutes for example?
i have try adding interval time but no use
thanx again
waiting
|
|
|
|
|
what is your problem with this code?
|
|
|
|
|
it doesnt do the movement up-down an down-up of the form in the corner of the screen
|
|
|
|
|
you must set timer.enabled= true
timer.interval =1000 milissecond
and
in timer event timer
copy your code for move
for example
buton1.left=buton1.left+100;(for x axis)
buton1.top=buton1.top+200;(for y axis)
|
|
|
|
|
i didi that still no use
|
|
|
|
|
I can see several problems:
- are the timers started when the button is pressed? What is the interval?
- It's possible that you need to send a redraw command on each tick (like update or invalidate or something)
- I'm confused the compiler doesn't complain about the flag variable. It's accessed across threads.
- why two timers? I believe 1 timer should be able to do the trick ?
the simplest way to go on about this IMHO is:
- 1 timer.
- 1 static boolean (true when button pressed, false when movement was done)
- 1 static counter that counts each passing of the the timer_tick handler.
- 1 static (final) stopvalue for when the work should stop.
in timer_tick you then check counter vs stopvalue (= amount of time), set the flag on false and reset the form, in an if(flag==true) block you can then move the form.
this is quick thinking, you can go into the details from there.
hope this helps...
|
|
|
|
|
thanks alot for your hints
i will try them
my problem is in how make the form come up again after its hidden in the corner after 2 minutes ?
|
|
|
|
|
if the goal is to hide the form you should use the Visible property (see here[^])
else you just reset the location of the form. You could keep the initial location in a Point variable and reset it to that when you reset the form.
|
|
|
|
|
the goal is not hiding the form
i want to move it down and after an interval make it move up again as its shown first
if i hide data order will be lost " bindingsource.movenext " so i just wan to delay its appearance wth the samem data >>> by move it up and down ,,up and down
how can i move it up again after passed time ?
hope u got me
thank you all again
i appreciate
|
|
|
|
|
I answered it already.
To move the form you need to change the location property. Possibly you'll need to force a redraw by calling invalidate or refresh or update or something.
If you want to set it back after an amount of time you need to store the original location before moving.
Moving is with X-Y coordinates (per pixel) where X is moving from left to right and Y from top to bottom.
So on a 1024x768 screen the top-left corner is 0,0 and the bottom-right corner 1024,768.
This should provide you with enough information to get you going.
|
|
|
|
|
I've put the comment on where to change the delay.
And I changed the interval to 1000 so the tick event execute every 1 second.
So you don't have to change the interval anymore.
|
|
|
|
|
yessssssss that wat i want
thanks alot midnight
thanks all
|
|
|
|
|
the form is comimg up and then come back down when click a button
what if i want the for to come down again after its shown for 1 minutes for example
have i add a timer test the
i will be gratefull
|
|
|
|
|
yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.
|
|
|
|
|
ok i will try it
thank u soo much
|
|
|
|
|
In wpf , using background worker i want to stop the sql server service than start sql service.
how i can achieve one by one, i mean once the sql server is stopped than only it gave a call for sql start service.
is there any way to do this ?, work completed method will call for both.
please help me with sample code.
help will be appreciated.
|
|
|
|
|
Have a look at the ServiceController [^] class.
This has a WaitForStatus [^] method that is ideal for your requirements.
You can even specify a timespan if you want to.
|
|
|
|
|
Hello, I have a doubt, how to save an image in the bank. I have a class to convert the image to byte and then save. I do not know the correct way, ask for help.
class:
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.IO;
using System.Drawing.Imaging;
using ImagensTeste.Dados;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace ImagensTeste.Negocio
{
class RegraNegocioFotos
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private string descricao;
public string Descricao
{
get { return descricao; }
set { descricao = value; }
}
private Image foto;
public Image Foto
{
get { return foto; }
set { foto = value; }
}
private Image foto1;
public Image Foto1
{
get { return foto1; }
set { foto1 = value; }
}
public byte[] ConvertImageToByteArray(Image image, ImageFormat imageFormat)
{
if (image == null)
return null;
MemoryStream ms = new MemoryStream();
image.Save(ms, imageFormat);
return ms.ToArray();
}
public Image ConvertByteArrayToImage(byte[] byteArray)
{
if (byteArray == null || byteArray.Length == 0)
{ return (null); }
return (Image.FromStream(new MemoryStream(byteArray)));
}
Banco dal = new Banco();
//Metodo inserir
public void InserirFoto()
{
try
{
dal.ComandoSQl("INSERT INTO tbFoto(descricao,foto, foto1) VALUES('" + Descricao + "','" + Foto + "','" + Foto1 + "')");
}
catch (Exception ex)
{
throw ex;
}
}
//Metodo atualizar
public void AtualizaFoto()
{
try
{
dal.ComandoSQl("UPDATE tbFoto set descricao='" + Descricao + "', foto='" + Foto + "', foto1='" + Foto1 + "'where id= " + Id + "");
}
catch (Exception ex)
{
throw ex;
}
}
//Metodo excluir
public void ExcluirFoto()
{
try
{
dal.ComandoSQl("DELETE FROM tbFoto where id= " + Id + "");
}
catch (Exception ex)
{
throw ex;
}
}
//Metodo preencher datagrid
public void PreencherDataGrid(DataGridView dgv)
{
dal.Consultar(dgv, "SELECT * FROM tbFoto");
}
//Metodo consultar codigo prefeitura
public void ConsultarId(DataGridView dgv)
{
dal.Consultar(dgv, "SELECT * FROM tbFoto WHERE id=" + Id + "");
}
//Metodo consultar razao social prefeitura
public void ConsultarNumero(DataGridView dgv)
{
dal.Consultar(dgv, "SELECT * FROM tbFoto WHERE descricao Like '%" + Descricao + "%'");
}
}
}
Form:
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.Data.SqlClient;
using System.Configuration;
using ImagensTeste.Negocio;
namespace ImagensTeste
{
public partial class frmFoto : Form
{
public frmFoto()
{
InitializeComponent();
//Alterar do app.config
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["ImagensTeste.Properties.Settings.fotosConnectionString"].ConnectionString =
ConfigurationManager.ConnectionStrings["ImagensTeste.Properties.Settings.fotosConnectionString"].ConnectionString;
config.Save(ConfigurationSaveMode.Full);
// ler novamente a seção do HD
ConfigurationManager.RefreshSection("connectionStrings");
}
RegraNegocioFotos negocio = new RegraNegocioFotos();
private void habilitarControles()
{
txtDescricao.Enabled = true;
}
public void LimparCampo()
{
this.LimparCampo(this);
}
public void LimparCampo(Control parent)
{
foreach (Control cont in parent.Controls)
{
if (cont is TextBox)
(cont as TextBox).Text = "";
if (cont is PictureBox)
(cont as PictureBox).Text = "";
if (cont is ComboBox)
(cont as ComboBox).Text = "";
if (cont is MaskedTextBox)
(cont as MaskedTextBox).Text = "";
if (cont is RadioButton)
(cont as RadioButton).Checked = false;
if (cont is CheckBox)
(cont as CheckBox).Checked = false;
if (cont is RichTextBox)
(cont as RichTextBox).Text = "";
if (cont is CheckedListBox)
{
foreach (ListControl item in (cont as CheckedListBox).Items)
item.SelectedIndex = -1;
}
if (cont is ListView)
(cont as ListView).Items.Clear();
// varre os filhos...
this.LimparCampo(cont);
}
}
private void btnGravar_Click(object sender, EventArgs e)
{
try
{
// Campos obrigatorios
if ((txtDescricao.Text != "") && (txtDescricao.Text != ""))
{
{
RegraNegocioFotos cln = new RegraNegocioFotos();
cln.Descricao = this.txtDescricao.Text;
//???
cln.Foto = this.picBrasao.Image;
cln.InserirFoto();
{
txtDescricao.Focus();
}
LimparCampo();
MessageBox.Show("Documento cadastrada com sucesso", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
{
txtDescricao.Focus();
}
}
else
{
MessageBox.Show("Campos Obrigatórios: Numero e Descrição", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
//Caso haja uma exceção será tratada neste código
MessageBox.Show("Não foi possível salvar pelo seguinte motivo: " + ex.Message);
}
}
private void btnProcurarImagen1_Click(object sender, EventArgs e)
{
openBrasao.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
DialogResult res = openBrasao.ShowDialog();
if (res == DialogResult.OK)
{
txtCaminho1.Text = openBrasao.FileName;
picBrasao.Image = Image.FromFile(openBrasao.FileName);
}
}
private void btnProcurarImagen2_Click(object sender, EventArgs e)
{
openLogo.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
DialogResult res = openLogo.ShowDialog();
if (res == DialogResult.OK)
{
txtCaminho2.Text = openLogo.FileName;
picLogo.Image = Image.FromFile(openLogo.FileName);
}
}
}
}
thank you...
|
|
|
|
|
I'm not going to try to read all that and try to figure out what you're doing wrong, but I'll point out two bad things that jump out at me:
dal.ComandoSQl("UPDATE tbFoto set descricao='" + Descricao + "', foto='" + Foto + "', foto1='" + Foto1 + "'where id= " + Id + "");
Don't use concatenation to build a query; use a parameterized query (this may actually be the whole problem).
catch (Exception ex)<br />
{<br />
throw ex;<br />
}
This is actually three problems in one.
Try to catch a specific Exception rather than all Exceptions.
Don't catch and rethrow without doing anything else.
If you rethrow (after doing something else), then just use throw , not throw ex .
In this case, you can remove the entire try/catch.
|
|
|
|